use-multi-state

1.0.0 • Public • Published

use-multi-state

A React Hook to simplify complex states.

What is this?

This is essentially just a wrapper around useState to shorten the amount of typing you would need to use it multiple times.

How does it work?

Here is a simple example:

import React from 'react'
import useMultiState from 'use-multi-state'

const example = () => {
  [
    [isFetching, setIsFetching],
    [data, setData],
    [error, setError]
  ] = useMultiState(false, null, null) // use initial state: isFetching: false, data: null, error: null

  return (
    <div>
      {isFetching ? (
        <div>Loading...</div>
      ) : error ? (
        <div>error.message</div>
      ) : data ? (
        <div>{data}</div>
      ) : null}
    </div>
  )
}

Readme

Keywords

Package Sidebar

Install

npm i use-multi-state

Weekly Downloads

1

Version

1.0.0

License

GPL-3.0

Unpacked Size

37.4 kB

Total Files

4

Last publish

Collaborators

  • alextaxiera