Skip to content

Um simples hook para gerenciamento de estados reativos usando localstorage e SWR

Notifications You must be signed in to change notification settings

felps-dev/react-ezglobalstate-hook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Um simples hook para gerenciamento de estados reativos usando localstorage e SWR

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages