0.0.1 • Published 3 years ago

@ervandra/use-setstate v0.0.1

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

use-setstate

React hook to useState and setState easily.

Install

npm install --save @ervandra/use-setstate

Usage

import * as React from 'react'

import { useSetState } from '@ervandra/use-setstate'

const Component = () => {
  const { useState, setState } = useSetState();
  const initialState = {
    isOpen: false,
    isLoading: true
  }
  const state = useState(initialState);
  const { isOpen, isLoading } = state;

  React.useEffect(() => {
    window.setTimeout(() => {
      setState({isOpen: true, isLoading: false})
    }, 1000);
  }, [])

  if(isLoading) return <p>Loading..</p>;

  return (
    <div>
      {isOpen && (
        <p>Is Open</p>
      )}
    </div>
  )
}

MIT © ervandra

0.0.1

3 years ago