![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
react-redux-action-dispatchers-hook
Advanced tools
Short: Transform action creators into action dispatchers
This simple make the code a tiny more clean. (See example's)
See demo here (editable codesandbox.io)
import React, { FC } from 'react'
import CreateActionDispatchers from 'react-redux-action-dispatchers-hook'
const MyActionCreators = {
action1: (name: string) => ({ type: 'action1', name }),
action2: (num: number) => ({ type: 'action2', num })
}
export const useMyActions = () => CreateActionDispatchers(MyActionCreators)
export const MyComponent: FC = () => {
const { action1, action2 } = useMyActions()
return (
<div>
<button onClick={() => action1('SomeName')}>Action 1</button>
<button onClick={() => action2(42)}>Action 2</button>
</div>
)
}
npm install react-redux-action-dispatchers-hook
Or
yarn add react-redux-action-dispatchers-hook
Create a plainObject with all your action creators like 'MyActionCreators'
const MyActionCreators = {
action1: (name: string) => ({ type: 'action1', name }),
action2: (num: number) => ({ type: 'action2', num })
}
Or
// action-creators are defined other place
const MyActionCreators = {
action1,
action2
}
Create hook by passing the plainObject into CreateActionDispatchers
import CreateActionDispatchers from 'react-redux-action-dispatchers-hook'
export const useMyActions = () => CreateActionDispatchers(MyActionCreators)
The action dispatcher can now be called the same way as the original action creators,
but they will also dispatch them (using reacts useDispatch
)
const MyComponent: FC = () => {
const { action1, action2 } = useMyActions()
return (
<div>
<button onClick={() => action1('SomeName')}>Action 1</button>
<button onClick={() => action2(42)}>Action 2</button>
</div>
)
}
The code below does the same thing.
As you can see, the only thing react-redux-action-dispatchers-hook
does is making the code a little more clean.
const MyComponent: FC = () => {
const dispatch = useDispatch()
const { action1, action2 } = MyActionCreators
return (
<div>
<button onClick={() => dispatch(action1('SomeName'))}>Action 1</button>
<button onClick={() => dispatch(action2(42))}>Action 2</button>
</div>
)
}
FAQs
transform action creators into action dispatchers
The npm package react-redux-action-dispatchers-hook receives a total of 1 weekly downloads. As such, react-redux-action-dispatchers-hook popularity was classified as not popular.
We found that react-redux-action-dispatchers-hook demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.