1.0.5 • Published 2 years ago

g-store v1.0.5

Weekly downloads
2
License
MIT
Repository
github
Last release
2 years ago

g-store

A Simplified Global store for React

Installation

npm install g-store

Usage

In the index.js file of the react app

import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';
import {Provider} from 'g-store';
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
  <Provider>
    <App />
  </Provider>
);

In You can use it in your Component

import { useGStore } from 'g-store'; 

function App() {
  const [state, setState] = useGStore(0,"UniqueGlobalStateName");
  
 const increment1=()=>{
    const tempState=state+1
    setState(tempState)
  }
  return (
    <>
     <button onClick={increment}>increment</button>
     <div >{state}</div>
    </>
  );
}

export default App;

Limitation

  1. You can use setState of useGStore to update the state only like this

      const tempState=state+1
        setState(tempState)

    You can't use like below

        setState((state)=>state+1)
  2. You have to pass a unique name to each state as a second argument in useGStore

     const [userName, setUserName] = useGStore("initial Value","userName");
      const [age, setAge] = useGStore(20,"age");

License

MIT

1.0.1

2 years ago

1.0.0

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

0.1.6

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago