Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
fetch-middleware
Advanced tools
const githubFetching = createAction(GITHUB_FETCHING)
const githubError = createAction(GITHUB_ERROR)
const githubSuccess = createAction(GITHUB_SUCCESS)
export const getUserFromGithub = username => ({
type : [
githubFetching,
githubSuccess,
githubError
],
payload : {
data : () => axios.get(`https://api.github.com/users/${username}`)
}
})
Note: you can pass more properties inside payload and it will be passed to success action.
Basic flux: loginSending -> data -> loginSuccess / loginError
The middleware will call loginSending before apiCall and loginSuccess when promise got resolved, if got an error, loginError will be called.
export const GITHUB_FETCHING = 'modules/Github/FETCHING'
export const GITHUB_SUCCESS = 'modules/Github/SUCCESS'
export const GITHUB_ERROR = 'modules/Github/ERROR'
import {handleActions} from 'redux-actions'
import {GITHUB_FETCHING, GITHUB_SUCCESS, GITHUB_ERROR} from './actions'
const initialState = {
fetching : false,
user : null
}
const reducer = handleActions({
[GITHUB_FETCHING]: (state, action) => ({
...state,
sending : true
}),
[GITHUB_SUCCESS]: (state, action) => ({
sending : false,
user : action.payload.data
}),
[GITHUB_ERROR]: (state, action) => ({
...state,
sending : false,
})
}, initialState);
export default reducer
const githubFetching = () => ({ type : 'GITHUB_FETCHING' })
const githubError = () => ({ type : 'GITHUB_ERROR' })
const githubSuccess = payload => ({
type : 'GITHUB_SUCCESS',
payload : payload
})
const initialState = {
fetching : false,
user : null
}
export const getUserFromGithub = username => ({
type : [
githubFetching,
githubSuccess,
githubError
],
payload : {
data : () => axios.get(`https://api.github.com/users/${username}`)
}
})
export default (state = initialState, action) => {
switch (action.type) {
case 'GITHUB_FETCHING':
return {...state,
fetching : true
}
case 'GITHUB_SUCCESS':
return {...state,
fetching : false,
user : action.payload.data
}
case 'GITHUB_ERROR':
return {...state,
fetching : false
}
default:
return state
}
}
FAQs
Middleware for Redux async actions
The npm package fetch-middleware receives a total of 6 weekly downloads. As such, fetch-middleware popularity was classified as not popular.
We found that fetch-middleware demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.