I was wondering if there are any issues using the useSyncExternalStore hook with Nextjs 13+ and the app directory? I know redux suggests you do no global stores Redux with nextjs due the the way nextjs handles requests. i was curious if the same would be true for the useSyncExternalStore
hook doing something like the following:
import { useSyncExternalStore } from 'react'
function createStore(initialStore) {
let store = initialStore
const listeners = new Set()
function setStore(newStore) {
store = newStore
listeners.forEach(listener => listener(store))
}
function subscribe(listener) {
listeners.add(listener)
return () => listeners.delete(listener)
}
function getStore() {
return store
}
function useStore() {
return useSyncExternalStore(subscribe, getStore)
}
return [useStore, setStore, getStore]
}
export const [useStore, setStore, getStore] = createStore({ count: 0 })
Are there some gotchas here that I should be aware of because this is technically a global store as well? Any input here would be appreciated before I go and use something that could possibly not work.