1.0.0 • Published 3 years ago

simple-state-mngt v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

simple-state-mngt

simple state management

NPM JavaScript Style Guide

Install

npm install --save simple-state-mngt

OR

npm install --save simple-state-mngt --force

Usage

Wrap your whole app with the default export like below example and pass an initial state

Index.js

import React from "react";
import ReactDOM from "react-dom";
import App from "./App";
import ContextProvider from "simple-state-mngt";
ReactDOM.render(
  <ContextProvider initialState="Basit">
    <App />
  </ContextProvider>,
  document.getElementById("root")
);

After wrapping your app now you can use state any where in app like below Grap useSimple module which is same as useState but with parameters because we passed initial state in Index.js. Just like useState it also return and array of two variables one is your state and another is method for state mutation.

App.js

import { useSimple } from "simple-state-mngt";
const App = () => {
  const [state, setState] = useSimple();
  return (
    <div className="App">
      <h1>Hi</h1>
      {state}
      <h1>
        <button onClick={() => setState("Ali")}>Change me</button>
      </h1>
    </div>
  );
};

export default App;

License

MIT © basitk41


This hook is created using create-react-hook.