This npm package provides easy-to-use and heighly performant state manager
To install this package, run the following command:
npm install create-external-store
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
This package is licensed under the MIT License. See the LICENSE file for more information.