0.0.2 • Published 3 years ago

create-global-state-hook v0.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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