JSPM

@jeswr/use-state

1.0.3
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q30269F
  • License MIT

React hook with same API as use state implemented using useReducer

Package Exports

  • @jeswr/use-state

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@jeswr/use-state) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

useState

React hook with same API as useState (plus some extensions) implemented using useReducer

GitHub license npm version build Dependabot semantic-release

Why

useReducer applies dispatch calls in the order in which they are made. The native useState functionality does not.

Usage

Using the traditional useState API

import { useState } from '@jeswr/use-state'

function MyReactComponent() {
  const [counter, setCounter] = useState(0);
  useEffect(() => {
    setCounter(1);
  }, [])
  return <div>{counter}</div>
}

Using the additional modifier parameter

import { useState } from '@jeswr/use-state'

function MyReactComponent() {
  const [counter, setCounter] = useState(0, props => props.value);
  useEffect(() => {
    setCounter({ value: 1 });
  }, [])
  return <div>{counter}</div>
}

License

©2021–present Jesse Wright, MIT License.