Skip to content

Commit

Permalink
feat: can pass initial data on createStore
Browse files Browse the repository at this point in the history
  • Loading branch information
Gading Nasution committed Dec 17, 2022
1 parent 09a9555 commit cd4ec67
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/swr-global-state/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ export function useStore<T, E = any>(data: StoreParams<T>, swrConfig?: SWRConfig
* @see https://github.com/gadingnst/swr-global-state#creating-a-store
*/
export function createStore<T, E = any>(data: StoreParams<T>, swrConfig?: SWRConfiguration) {
return () => useStore<T, E>(data, swrConfig);
return (initial?: T) => useStore<T, E>({
...data,
initial: initial || data.initial
}, swrConfig);
}

export default useStore;

0 comments on commit cd4ec67

Please sign in to comment.