react-usetrackedstate
v0.0.9
Published
Tracked property for react and react native similer to Ember object
Downloads
5
Maintainers
Readme
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: "[email protected]"
};
user.set(responseFromApi);
user.package = "Github";
}, [])
return (
<>
<p>{user.name}</p>
<p>{user.email}</p>
<p>{user.package}</p>
</>
)
}
Codesandbox Example