You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

@paprika/seducer

Package Overview
Dependencies
Maintainers
3
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@paprika/seducer

Seducer (simple reducer) is a wrapper on top of React.useReducer, making it easier to use


Version published
Maintainers
3
Created

Readme

Source

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}
    </>
  );
}

Keywords

FAQs

Package last updated on 16 Jul 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc