create-external-store
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

create-external-store

This npm package provides easy-to-use and heighly performant state manager

Installation

To install this package, run the following command:

npm install create-external-store

Usage

createExternalStore return a hook and a setter.

Use the hook in the component, use the setter anywhere. When you use the setter setNumber(2) components which use the hook useNumber() would be rerendered and display the new value.

const [useNumber, setNumber] = createExternalStore<number>(1)

setInterval(() => {
  setNumber(num => num + 1)
}, 1000)

function App() {
  const number = useNumber()
  const numberSquared = useNumber(num => num*num)
  return (
    <>
      <div>Number {number}</div>
      <div>Number squared {numberSquared}</div>
    </dib>
  )
}

export default App

License

This package is licensed under the MIT License. See the LICENSE file for more information.

Package Sidebar

Install

npm i create-external-store

Weekly Downloads

3

Version

1.0.3

License

MIT

Unpacked Size

9.23 kB

Total Files

15

Last publish

Collaborators

  • taylor-ben