rustamglobalstate

1.0.1 • Public • Published

My React Global State

A simple global state management solution for React applications. This package provides a context provider and custom hook for managing global state with ease.

Installation

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

Readme

Keywords

none

Package Sidebar

Install

npm i rustamglobalstate

Weekly Downloads

0

Version

1.0.1

License

ISC

Unpacked Size

12.7 kB

Total Files

3

Last publish

Collaborators

  • rustam25