0.0.9 • Published 3 years ago
react-usetrackedstate v0.0.9
react-usetrackedstate
How to use
Installation
$ npm i react-usetrackedstate
$ yarn add react-usetrackedstate
import useTrackedState from 'react-usetrackedstate'
function MyComponent(){
const counter = useTrackedState({ value: 0 })
useEffect(() => {
setInterval(() => {
counter.value++;
}, 1000);
}, [])
return (
<p>{counter.value}</p>
)
}
import useTrackedState from 'react-usetrackedstate'
function MyComponent(){
const user = useTrackedState({})
useEffect(() => {
const responseFromApi = {
name: "npm",
email: "npm@npm.com"
};
user.set(responseFromApi);
user.package = "Github";
}, [])
return (
<>
<p>{user.name}</p>
<p>{user.email}</p>
<p>{user.package}</p>
</>
)
}
Codesandbox Example