1.1.18 • Published 3 years ago

react-redux-actions-hook v1.1.18

Weekly downloads
107
License
MIT
Repository
github
Last release
3 years ago

react-redux-actions-hook

useActions(actions, dependencies = [])

Hook to use actions bound to dispatch.

const actions : Object = useActions(actions: Object, dependencies : Array = []);

Example

import { useActions } from 'react-redux-actions-hook'
import * as rawActions from './actions'

export default const MyComponent = () => {
  const actions = useActions(rawActions);
  return (
    <button onClick={actions.goHome}>Home</button>
  )
}

createActionsHook(actions) => Function useActions([dependencies])

Factory to create useActions methods for use in action creator modules.

const useActions : Function = createActionsHook(actions : Object = []);

This hook factory can be used in with your action creators in order to expose a useActions() hook that can be used in your components.

Example

// actions.js
import { createActionsHook } from 'react-redux-actions-hook'

export const doSomething = e => ({  
  type: 'admin-button-action',
  payload: e.target.value,
})

export const useActions = createActionsHook({ doSomething })

// AdminButton.jsx
import { useSelector } from 'react-redux'
import { useActions } from './actions'
 
export const MyComponent = ({ id, text }) => {
  const action = useActions();
  return (
    <button
      class="admin-button"
      onClick={action.doSomething}
      value={id}
    >
      {text}
    </button>
  )
}

When passing an array of dependencies to useActions the bound actions are memoized.

License

MIT License

1.1.18

3 years ago

1.1.17

3 years ago

1.1.16

4 years ago

1.1.15

4 years ago

1.1.14

4 years ago

1.1.13

4 years ago

1.1.12

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago