Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

React Hook useReducer with cancelable dispatch of thunks

License

NotificationsYou must be signed in to change notification settings

PedroBern/react-hook-use-cancelable-thunk-reducer

Repository files navigation

Codecov CoverageBuild Statusdependencies

Custom implementation of react hookuseReducer that will cancel all dispatched actions if the component is unmounted and allows to dispatchthunk actions (that will be canceled either).

demo-gif

Open oncodesanbox.

Installation

yarn add use-cancelable-thunk-reducernpm i use-cancelable-thunk-reducer

useCancelableThunkReducer

importuseCancelableThunkReducerfrom'use-cancelable-thunk-reducer';const[state,dispatch]=useCancelableThunkReducer(reducer,initialState,callback,init);

reducer

useReducer first argument.

initialState

useReducer second argument.

callback

default isundefined, if is afunction, when some action is canceled it is called with the action argument:callback(action).

init

useReducer last argument.

Thunk action

The thunk actions receive(dispatch, getState) args.

constthunkAction=args=>async(dispatch,getState)=>{dispatch({type:ACTION_SENT});conststate=getState();  ...}

About

React Hook useReducer with cancelable dispatch of thunks

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors2

  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp