Skip to content

Instantly share code, notes, and snippets.

@koderhun
Created November 7, 2022 10:58
Show Gist options
  • Save koderhun/58b78b8f779009237e1651a47889cdb1 to your computer and use it in GitHub Desktop.
Save koderhun/58b78b8f779009237e1651a47889cdb1 to your computer and use it in GitHub Desktop.
useActions для redux-toolkit
// hooks для того чтобы не импортировать в каждый компонент redux dispath
// можно просто импортировать этот файл и брать доступные экшаны
import { useDispatch } from 'react-redux'
import { bindActionCreators } from 'redux'
import { githubActions } from '../store/github/github.slice'
// список доступных экшенов
const actions = {
...githubActions,
}
export const useActions = () => {
const dispatch = useDispatch()
return bindActionCreators(actions, dispatch)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment