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

This package provides small helpers to improve your experience with redux-thunk

License

NotificationsYou must be signed in to change notification settings

Shastel/thunk-helpers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This package provides small helpers to improve your experience with redux-thunk


Installation

npm install thunk-helpers

Usage

import{withDispatch,withState,withSelectors,withDispatchAction,withStateAction,withSelectorsAction,}from'thunk-helpers';// withDispatch expects function as argument// returned value will be automatically dispatched// it works with sync function and promises as well;// you may return object or arrayconstfetchUser=(id)=>withDispatch(async(/* dispatch, getState, ...dependencies */)=>{constuser=awaitfetch(`/user/${id}`);return{type:'USER_FETCHED',payload:user};});// withState, works same as withDispatch, but// automatically call getState, and provide state// as argument to your actionconstexampleAction=()=>withState(async(dispatch,state)=>{const{ smth}=state;return{type:'EXAMPLE',payload:smth}});// withSelectors works pretty same as withState,// but accepts array of selector functions or 1 function// and replace getState with result of those functions()=>withSelectors(async(dispatch,[smth]))=>{return{type:'EXAMPLE',payload:smth}},[someSelectorFunction])// If you don't need provide any param from outside// All functions have 'action creator',// In this case inner function will be created only onceconstfetchUser=withDispatchAction(async(/* dispatch, getState, ...dependencies */)=>{constuser=awaitfetch('/user/me');return{type:'USER_FETCHED',payload:user};});constexampleAction=withStateAction(async(dispatch,state)=>{const{ smth}=state;return{type:'EXAMPLE',payload:smth}});withSelectorsAction(async(dispatch,[smth]))=>{return{type:'EXAMPLE',payload:smth}},[someSelectorFunction])

LICENSE

MIT

About

This package provides small helpers to improve your experience with redux-thunk

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp