redux saga fetch json
// USER ACTION CREATOR
export const userState = {};
export const RECEIVED_ALL = "RECEIVED_ALL";
export const REQUEST_ALL = "REQUEST_ALL";
export const userRequestAllActionCreator = (type) => ({
type: type
});
// USER REDUCER
import { userState, RECEIVED_ALL } from "../actions/user";
export const userReducer = (state = userState, action) => {
switch (action.type) {
case RECEIVED_ALL:
return action.payload;
default:
return state;
}
};
// USER SAGA
import axios from "axios";
import { put, takeLatest } from "redux-saga/effects";
import { REQUEST_ALL, RECEIVED_ALL } from "../actions/user";
function* userReceiveAll() {
const { data } = yield axios.get("https://jsonplaceholder.typicode.com/users");
yield put({ type: RECEIVED_ALL, payload: data });
}
export function* userSagaAll() {
yield takeLatest(REQUEST_ALL, userReceiveAll);
}
Also in JavaScript:
- js filter
- Adding an event listener to an element that doesn't exist yet
- react native create button
- if condition in class angular 8
- how to write a program that alerts the first 3 letters of the current day in javascript
- remove last 3 characters from string javascript
- lifecycle methods react
- Warning: Failed child context type: Invalid child context `virtualizedCell.cellKey` of type
- js object entries
- what is @ atsign in first of file path nodejs
- javascript format date yyyy-mm-dd hh:mm:ss to dd-mm-yyyy hh:mm am/pm
- javascript loop through array backwords
- mm dd yyyy how to get date in this format in javascript
- javascript get random number
- React get method
- javascript funtion
- get the first word of a string javascript
- email validation regex
- javascript angle equation of a line
- jquery change picture source
- Javascript get element height and width
- create dynamic fields in react
- latest rn fatch blob package download
- json_encode escape \