react-use-thunk-reducer

0.1.1 • Public • Published

useThunkReducer

To install run

npm i react-use-thunk-reducer

or

yarn add react-use-thunk-reducer

Usage

import React from "react";
import useThunkReducer from "react-use-thunk-reducer";

const reducer = (state, action) => {
  if (action.type === "HI") {
    return action.value;
  } else {
    return state;
  }
};

const changeValueAsync = () => ({ dispatch, getState }) => {
  setTimeout(() => {
    dispatch({ type: "HI", value: Math.random() });
  }, 1000);
};

const App = () => {
  const [state, thunk] = useThunkReducer(reducer, "INITIAL");
  return <button onClick={() => thunk(changeValueAsync())}>{state}</button>;
};

export default App;

Package Sidebar

Install

npm i react-use-thunk-reducer

Weekly Downloads

1

Version

0.1.1

License

none

Unpacked Size

3.69 kB

Total Files

8

Last publish

Collaborators

  • erodactyl