1.0.1 • Published 5 years ago

@auzmartist/react-hooks v1.0.1

Weekly downloads
2
License
ISC
Repository
github
Last release
5 years ago

React Hooks

Helpful hooks to satisfy common reactive patterns.

Installation

npm i @auzmartist/react-hooks

Usage

useComputed

import {useComputed} from '@auzmartist/react-hooks'

function MyReactComponent({a, b}) {
  // THIS ALL-TOO-COMMON PATTERN

  const [sum, setSum] = useState(0)
  useEffect(() => {
  	setSum(a + b)
  }, [a, b])

  // BECOMES

  const sum = useComputed((current) => a + b, [a, b])

  return <div>
    {a} + {b} = {sum.current}
  </div>
}

// renders 4 + 3 = 7

useComputed also handles asynchronously computed values.

function myReactComponent({a, b}) {
  const response = useComputed(() => doSomeAsync(a, b), [a, b], initial)
}

For async computed properties, an initial value will be assigned synchronously.

1.0.1

5 years ago

1.0.0

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago