Created
August 3, 2020 17:37
-
-
Save Rajatgms/e408110c316a0fd6272970d35519567e to your computer and use it in GitHub Desktop.
Loader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createSlice } from '@reduxjs/toolkit'; | |
const loaderSlice = createSlice({ | |
name: 'loader', | |
initialState: false, | |
reducers: { | |
startLoader: (state, action) => action.payload, | |
}, | |
extraReducers: builder => { | |
builder | |
.addMatcher( | |
action => action.type.endsWith('/pending') && 'requestId' in action.meta, | |
() => true, | |
) | |
.addMatcher( | |
action => ( | |
action.type.endsWith('/fulfilled') || | |
action.type.endsWith('/rejected')) && | |
'requestId' in action.meta, | |
() => false, | |
) | |
; | |
}, | |
}); | |
const { actions, reducer } = loaderSlice; | |
export const { startLoader } = actions; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment