2.0.4 • Published 2 years ago

@paprika/seducer v2.0.4

Weekly downloads
29
License
-
Repository
github
Last release
2 years ago

Seducer

React.useReducer is an awesome hook but more often than not it is overshadow by its relative React.useState which is easier and simpler to use.

Personally, I think is mostly by some of the following reasons:

  • Reducers are not the bread and butter of all react-developers unlike React.useState making it harder to memorize.
  • Apart from simple examples React.useReducer requires some boilerplate to make it "functional".
  • To make it consumable across different components you need to pair it with the React.createContext and you will need more boilerplate to use it.
  • And because all above, our beloved React.useState is picked first than React.useReducer each time

To mitigate some of these reasons, Seducer (simple reducer) borned which is a wrapper on top of React.useReducer, making it easier to use and with a more friendly API.

Seducer provides two hooks that you can consume useSeducer and useSeducerWithContext.

useSeducer example

import { useSeducer } from "@paprika/seducer";
export default function App() {
  function up(state) {
    return state + 1;
  }
  function down(state) {
    return state - 1;
  }
  const [state, dispatch, action] = useSeducer({ up, down }, 0);

  return (
    <>
      {/** alternative you can dispatch("up") directly */}
      <Button onClick={() => dispatch(action.up)}>+</Button>
      <Button onClick={() => dispatch(action.down)}>-</Button>
      {state}
    </>
  );
}
2.0.4

2 years ago

2.0.4-next.0

2 years ago

2.0.3

3 years ago

2.0.3-next.0

3 years ago

2.0.2

3 years ago

2.0.2-next.0

3 years ago

2.0.1

3 years ago

2.0.1-next.0

3 years ago

2.0.0

3 years ago

1.2.1-alpha.2

3 years ago

1.2.1-alpha.0

3 years ago

1.2.1-alpha.1

3 years ago

1.2.0

3 years ago

1.1.2

3 years ago

1.1.0

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago