A React Custom Hook for Zustand state management library to simplify hydration handling.
# npm
npm install @codebayu/use-hydration-zustand
# yarn
yarn add @codebayu/use-hydration-zustand
import { useHydrationZustand } from '@codebayu/use-hydration-zustand';
import create from 'zustand';
// Your Zustand store
const useStore = create((set) => ({
// Your store definition here
}));
function MyComponent() {
// Use the useHydrationZustand hook
const isHydrated = useHydrationZustand(useStore);
return (
<div>
{isHydrated ? (
items.map((item) => <Card {...item} key={item.id} />)
) : (
<Loading />
)}
</div>
);
}
export default MyComponent;
useHydrationZustand(store)
A hook for Zustand that simplifies hydration handling.
Parameters
store (UseBoundStore<any>)
: The Zustand store.
Returns
boolean
: true if the store has finished hydration, false otherwise.
This project is licensed under the MIT License - see the LICENSE file for details.