1.0.6 • Published 5 years ago

useloggedreducer v1.0.6

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

useLoggedReducer

Use React's useReducer hook with redux-logger for debugging

Getting Started

Installing

npm i useloggedreducer

Example

import React from "react";
import { useLoggedReducer } from "useloggedreducer";

const initialState = { count: 0 };

function reducer(state, action) {
  switch (action.type) {
    case "reset":
      return initialState;
    case "increment":
      return { count: state.count + 1 };
    case "decrement":
      return { count: state.count - 1 };
    case "set":
      return { count: action.count };
    default:
      return { count: state.count };
  }
}

function App() {
  const [state, dispatch] = useLoggedReducer(reducer, initialState);
  return (
    <>
      Count:{" "}
      <input
        type="number"
        value={state.count}
        onChange={e => dispatch({ type: "set", count: +e.target.value })}
      />
      <button onClick={() => dispatch({ type: "reset" })}>Reset</button>
      <button onClick={() => dispatch({ type: "increment" })}>+</button>
      <button onClick={() => dispatch({ type: "decrement" })}>-</button>
    </>
  );
}

Built With

  • React - A JavaScript library for building user interfaces
  • redux-logger - Logger for Redux

License

This project is licensed under the MIT License - see the LICENSE.md file for details

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago