Next.js Discord

Discord Forum

NextJS Zustand revalidate data

Unanswered
New Guinea Freshwater Crocodile posted this in #help-forum
Open in Discord
New Guinea Freshwater CrocodileOP
using pretty much the standard nextjs example, where memberData was fetched in a rsc and passed down, i have a lot of cases where I am calling router.refresh() and getting fresh data for the same page, is it just as simple as the useEffect here? not getting any errors and seems to work but just thought id make sure

export const CounterStoreProvider: FC<CounterStoreProviderProps> = ({ children, memberData }) => {
    const storeRef = useRef<CounterStoreApi>();

    if (!storeRef.current) {
        storeRef.current = createCounterStore(memberData);
    }

    useEffect(() => {
        if (storeRef.current) {
            storeRef.current.setState(memberData);
        }
    }, [memberData]);

    return (
        <CounterStoreContext.Provider value={storeRef.current}>{children}</CounterStoreContext.Provider>
    );
};

1 Reply

Short-tailed Albatross
hey
hoe did you handle clearing the state/ updating states on new pages,
in my case i am using zustand when the entityPage Pnloads and that might be tricky if there are many entities to be opened,
so was wondering how to clear upon change
any advice will be amazing, thank you