0.0.9 • Published 3 years ago

react-usetrackedstate v0.0.9

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

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

0.0.9

3 years ago

0.0.8

3 years ago

0.0.5

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago