A simple global state management solution for React applications. This package provides a context provider and custom hook for managing global state with ease.
To install the package, use npm or yarn:
npm install rustamglobalstate
Usage
1. Setup the Global State Provider
Wrap your application's root component with the GlobalStateProvider:
jsx
Copy code
import React from 'react';
import ReactDOM from 'react-dom';
import { GlobalStateProvider } from 'rustamglobalstate';
import App from './App';
ReactDOM.render(
<GlobalStateProvider>
<App />
</GlobalStateProvider>,
document.getElementById('root')
);
2. Use the Global State in Your Components
Use the useGlobalState hook to access and update the global state:
jsx
Copy code
import React from 'react';
import { useGlobalState } from 'rustamglobalstate';
const MyComponent = () => {
const { state, dispatch } = useGlobalState();
const handleUpdate = () => {
dispatch({ key: 'myKey', value: 'myValue' });
};
return (
<div>
<button onClick={handleUpdate}>Update State</button>
<div>Stored Value: {state.myKey}</div>
</div>
);
};
export default MyComponent;
Feel free to contact at rustam86310@gmail.com