npm

react-usetrackedstate

0.0.9 • Public • Published

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

Package Sidebar

Install

npm i react-usetrackedstate

Weekly Downloads

0

Version

0.0.9

License

ISC

Unpacked Size

2.88 kB

Total Files

3

Last publish

Collaborators

  • jsfit