Skip to content
Discussion options

You must be logged in to vote

@b4ljk yes. I had to create a special hook for retrieving the data in an async way. Not ideal, but does the job:

/**
 * Use this function when you want to fix the "hydration" error in NextJS
 * @param store
 * @param callback
 */
export const useAsyncStore = <T, F>(store: (callback: (state: T) => unknown) => unknown, callback: (state: T) => F) => {
    const result = store(callback) as F
    const [data, setData] = useState<F>()

    useEffect(() => {
        setData(typeof result === 'function' ? () => result : result)
    }, [result])

    return data
}

/**
 * Use this function when you want to fix the "hydration" error in NextJS
 * @param key
 */
export const useAsyncStoreValue = <K e…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by IonelLupu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants