0.1.4 • Published 4 years ago

react-ezglobalstate-hook v0.1.4

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

React-EZGlobalState-Hook

A reactive state with localstorage and SWR.

Reference

npm i --save react-ezglobalstate-hook
or
yarn add react-ezglobalstate-hook

import {
    useGlobalState,
    setGlobalState
} from 'react-ezglobalstate-hook';

useGlobalState(key: string, initialValue: any):

const myState = useGlobalState("unique_key", "default");

setGlobalState(key: string, value: any):

setGlobalState("unique_key", "value");

Example

import {
    useGlobalState,
    setGlobalState
} from 'react-ezglobalstate-hook';

export default function Component(){
    //Is this case, Hello World is the primary value if we
    //never had stored this value before.
    const myState = useGlobalState("myState", "Hello World");

    function handleChange(){
        setGlobalState("myState", "Good Bye World");
    }

    return (
        <div>
            <span>{`Actual value for myState is: ${myState}`}</span>
            <button onClick={handleChange}>Change Name</button>
        </div>
    )
}

License

MIT

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago