create-global-hook
Advanced tools
+3
-2
| { | ||
| "name": "create-global-hook", | ||
| "version": "0.0.1", | ||
| "version": "0.1.0", | ||
| "description": "Takes an aribtrary React hook and makes it globally stateful", | ||
| "main": "index.js", | ||
| "main": "build/create-global-hook.js", | ||
| "types": "build/create-global-hook.d.ts", | ||
| "repository": "https://github.com/garbles/create-global-hook", | ||
@@ -7,0 +8,0 @@ "author": "Gabe Scholz <hi@gabe.pizza>", |
+10
-1
@@ -10,3 +10,5 @@ Takes an aribtrary React hook and makes it globally stateful. | ||
| const [hook, Provider] = createHook((value: number) => React.useState(value)); | ||
| const [hook, Provider] = createGlobalHook((value: number) => | ||
| React.useState(value) | ||
| ); | ||
@@ -19,5 +21,12 @@ const App = () => { | ||
| const OtherApp = () => { | ||
| const [state, setState] = hook(); | ||
| // same state here | ||
| }; | ||
| ReactDOM.render( | ||
| <Provider value={0}> | ||
| <App /> | ||
| <OtherApp /> | ||
| </Provider>, | ||
@@ -24,0 +33,0 @@ document.getElementById("root") |
3125
5.97%34
36%