Skip to content

Globix is the easiest way to bring global state to your React App

Notifications You must be signed in to change notification settings

hyposlasher/globix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

React Global State Hook

Globix is the easiest way to bring global state to your React App

Installing

npm i --save globix

Usage

Wrap your Root Component with GlobixProvider and pass optional initialValues props:

import { GlobixProvider } from 'globix';

ReactDOM.render(
  <GlobixProvider initialState={{name: 'Daron Malakian'}}>
    <App />
  </GlobixProvider>,
  document.getElementById('root')
);

Get global state anywhere in your application:

import { useGlobix } from 'globix';

const SomeComponent = () => {
  const { globaslState } = useGlobix();

  return <p>{globalState.name}</p>;
}

Set global state from anywhere you want:

import { useGlobix } from 'globix';

const AnotherComponent = () => {
  const { globalState, setGlobalState } = useGlobix();

  const handleClick = () => {
    setGlobalState({
      ...globalState,
      newValue: 'new value'
    })
  }

  return <button onClick={handleClick}>change name</button>
}

Authors

License

This project is licensed under the MIT License

About

Globix is the easiest way to bring global state to your React App

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published