Security News
PyPI’s New Archival Feature Closes a Major Security Gap
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
partial-hydrate
Advanced tools
Partial React hydration wrapper component based on screen width for faster responsive performances
Provides a <PartialHydrate>
component that conditionally skips hydrating children by removing them from the DOM before the first client render. Removing them before ensures hydration is successful and there are no hydration mismatch errors.
npm i partial-hydrate
<PartialHydrate
when={() => {
window.innerWidth <= 680
}}
>
{/* My mobile component */}
</PartialHydrate>
minWidth
: will render if window width is greater than minWidth
value.maxWidth
: will render if window width is lesser than maxWidth
value.when()
: function
that must return true
for the render to happen.You can use the minWidth
and/or maxWidth
props individually or together to conditionally render components based on the window width. Here's an example:
const MyComponent = () => {
return (
<PartialHydrate minWidth={768}>
{ /* Rendered if window width is greater than or equal to 768 pixels */ }
</PartialHydrate>
<PartialHydrate maxWidth={1024}>
{ /* Rendered if window width is less than or equal to 1024 pixels */ }
</PartialHydrate>
<PartialHydrate minWidth={768} maxWidth={1024}>
{ /* Rendered if window width is between 768 and 1024 pixels (inclusive) */ }
</PartialHydrate>
)
}
The when()
prop allows for a custom condition based on a function. It is particularly useful for your dynamic conditions. For example:
const MyComponent = () => {
return (
<PartialHydrate when={() => someDynamicCondition()}>
{/* Rendered if the custom condition specified in the `when()` function is true */}
</PartialHydrate>
)
}
When using React's server-side rendering, we often need to render components on the server even if they are conditional on the client e.g. hidden based on window width.
In order for hydration to succeed, the first client render must match the DOM (which is generated from the HTML returned by the server), otherwise we will get hydration mismatch errors. This means the component must be rendered again during the first client render.
However, hydration is expensive, so we really don't want to pay that penalty only for the element to be hidden or removed immediately afterwards.
So is this another react responsive rendering library? Nope. If the prop conditions are not met, then <PartialHydrate>
's children are never rendered.
Also, keep in mind that using <PartialHydrate>
does not work on window resize and it is not meant to!
Based on a gist by OliverJAsh. Developed, modified and maintained by George Cht.
FAQs
Partial React hydration wrapper component based on screen width for faster responsive performances
The npm package partial-hydrate receives a total of 3 weekly downloads. As such, partial-hydrate popularity was classified as not popular.
We found that partial-hydrate demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
Research
Security News
Malicious npm package postcss-optimizer delivers BeaverTail malware, targeting developer systems; similarities to past campaigns suggest a North Korean connection.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.