Skip to content

Instantly share code, notes, and snippets.

@samuelint
Created February 2, 2024 15:09
Show Gist options
  • Save samuelint/ce7ab93cb1f009fb090967b92fae82b5 to your computer and use it in GitHub Desktop.
Save samuelint/ce7ab93cb1f009fb090967b92fae82b5 to your computer and use it in GitHub Desktop.
use-hydrate-example--client-side-component.tsx
'use client';
import { useHydrate } from 'use-hydrate';
import { setData } from './redux/my.slice';
import { selectData } from './redux/data.selector';
interface Props {
existing?: MyData[]
}
export default function MyClientSideComponent({ existing = [] }: Props) {
const data = useHydrate({ initial: existing, action: setData, selector: selectData });
return (
<div className="flex">
{ data }
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment