create-external-store
v1.0.3
Published
external store for react
Downloads
9
Maintainers
Readme
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.