Skip to content

Instantly share code, notes, and snippets.

@chadmuro
Created August 27, 2023 04:57
Show Gist options
  • Save chadmuro/a63157ee5fd93707477fb13030cdd3fd to your computer and use it in GitHub Desktop.
Save chadmuro/a63157ee5fd93707477fb13030cdd3fd to your computer and use it in GitHub Desktop.
hookstate
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