npm.io
0.0.2 • Published 5 years ago

create-global-state-hook

Licence
MIT
Version
0.0.2
Deps
0
Size
2 kB
Vulns
0
Weekly
0

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>
    )
}