react-promise-hook

1.0.1 • Public • Published

React Promise Hook

React hook with the promise that gives you an ability to react on after set effect

Usage

import usePromiseHook from 'react-promise-hook'
 
const App = () => {
  const [test, setTest] = usePromiseHook(0)
 
  if (!test) {
    setTimeout(() => {
      setTest(42).then(() => console.log('UPDATED'))
    }, 2000)
  }
 
  return (
    <div className="App">
      <header className="App-header">
        <span role="img" aria-label="img">
          🤓
        </span>
        The Answer is {test}
      </header>
    </div>
  )
}
 
export default App

Demo

demo

Installation

 npm i react-promise-hook

or

 yarn add react-promise-hook

Made with ♥ by nudelx

Package Sidebar

Install

npm i react-promise-hook

Weekly Downloads

1

Version

1.0.1

License

ISC

Unpacked Size

498 kB

Total Files

6

Last publish

Collaborators

  • nudelx