1.1.1 • Published 2 years ago

use-state-hook v1.1.1

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

use-state-hook

A simple react hook for global state management

Installation

Install use-state-hook with npm

  npm install use-state-hook

Usage/Examples

import useHookState from 'use-state-hook'

function App() {

  const {setHookState} = useHookState();

  useEffect(() => {
  setHookState(0); //Initiaize the global state value in the wrapper component
  }, []);
  
  return (
    <CounterDisplay />
    <CountIncrementButton />
  )
}

function CounterDisplay() {
  const {hookState} = useHookState(); // Access the global state
  return (
    <span>{hookState}</span>
  )
}

function CountIncrementButton() {
  const {hookState,setHookState} = useHookState(); //setHookState function to update global state 
  return(
    <button onClick={() => setHookState(hookState+1)}>Increment count!</button>
  )
}

Screenshots

App Screenshot

1.1.1

2 years ago

1.1.0

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago