CoastalCommitsPastes/client/lib/hooks/use-shared-state.ts

12 lines
293 B
TypeScript
Raw Permalink Normal View History

import useSWR from "swr"
// https://2020.paco.me/blog/shared-hook-state-with-swr
const useSharedState = <T>(key: string, initial?: T) => {
2022-03-23 18:42:22 -04:00
const { data: state, mutate: setState } = useSWR(key, {
fallbackData: initial
})
return [state, setState] as const
}
export default useSharedState