mirror of https://github.com/MaxLeiter/Drift
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
12 lines
308 B
TypeScript
12 lines
308 B
TypeScript
import useSWR from "swr"
|
|
|
|
// https://2020.paco.me/blog/shared-hook-state-with-swr
|
|
const useSharedState = <T>(key: string, initial?: T) => {
|
|
const { data: state, mutate: setState } = useSWR(key, {
|
|
fallbackData: initial
|
|
})
|
|
return [state, setState] as const
|
|
}
|
|
|
|
export default useSharedState
|