Created
August 27, 2023 04:57
-
-
Save chadmuro/a63157ee5fd93707477fb13030cdd3fd to your computer and use it in GitHub Desktop.
hookstate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { hookstate, useHookstate } from '@hookstate/core'; | |
const globalState = hookstate(0); | |
setInterval(() => globalState.set(p => p + 1), 3000) | |
export const ExampleComponent = () => { | |
const state = useHookstate(globalState); | |
return <> | |
<b>Counter value: {state.get()}</b> (watch +1 every 3 seconds) {' '} | |
<button onClick={() => state.set(p => p + 1)}>Increment</button> | |
</> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment