diff --git a/docs/createGlobalState.md b/docs/createGlobalState.md index b7451765..0e028134 100644 --- a/docs/createGlobalState.md +++ b/docs/createGlobalState.md @@ -1,6 +1,6 @@ # `useGlobalState` -A React hook which creates a globally shared state. +A React hook that creates a globally shared state. ## Usage @@ -30,3 +30,32 @@ const Demo: FC = () => { ); }; ``` + +It also allows initializing the state with a function and using a function in the setState: + +```tsx +const useGlobalValue = createGlobalState(() => 0); + +const CompA: FC = () => { + const [value, setValue] = useGlobalValue(); + + return ; +}; + +const CompB: FC = () => { + const [value, setValue] = useGlobalValue(); + + return ; +}; + +const Demo: FC = () => { + const [value] = useGlobalValue(); + return ( +
+

{value}

+ + +
+ ); +}; +```