create-global-state-hook
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

crete-global-state-hook

Creates a hook like useState but all instances will have a single shared storage

Example

import creteGlobalStateHook from 'crete-global-state-hook'

const useGlobalCounter = createGlobalStateHook(0)

export default function GlobalCounter() {
    const [count, setCount] = useGlobalCounter()
    return (
        <div>
            <input type="button" value="-" onClick={() => setCount(count - 1)} />
            {count}
            <input type="button" value="+" onClick={() => setCount(count + 1)} />
        </div>
    )
}

Readme

Keywords

none

Package Sidebar

Install

npm i create-global-state-hook

Weekly Downloads

20,854

Version

0.0.2

License

MIT

Unpacked Size

2.25 kB

Total Files

4

Last publish

Collaborators

  • termosa