redux-thunk

Populating reaxt ag grid after API call

走远了吗. 提交于 2021-02-11 13:48:53
问题 I am new to react and stuck at this point. I am doing an async API call in action dispatcher to fetch a list of patient data.Once the data is returned I need to render it in ag grid. This is my code: import React, { useEffect, useState } from 'react'; import { connect } from 'react-redux'; import { fetchPatientsStartAsync } from '../../redux/patients/patients.actions'; import { PatientContainer } from './patients.styles'; import { AgGridReact } from 'ag-grid-react'; import 'ag-grid/dist

Redux thunk - how to prevent it from making unnecessary API request?

≯℡__Kan透↙ 提交于 2021-02-07 17:26:35
问题 I have action.js file like this: import axios from 'axios'; export const SEARCH_TERM = 'SEARCH_TERM'; export const SAVE_SEARCH = 'SAVE_SEARCH'; export function search(query) { const githubApi = `https://api.github.com/search/repositories?q=${query}&sort=stars&order=desc`; const request = axios.get(githubApi); return (dispatch) => { request.then(({ data: dataFromGithub }) => { dispatch({ type: SEARCH_TERM, payload: query }); dispatch({ type: SAVE_SEARCH, payloadOne: query, payloadTwo:

Redux thunk - how to prevent it from making unnecessary API request?

↘锁芯ラ 提交于 2021-02-07 17:25:31
问题 I have action.js file like this: import axios from 'axios'; export const SEARCH_TERM = 'SEARCH_TERM'; export const SAVE_SEARCH = 'SAVE_SEARCH'; export function search(query) { const githubApi = `https://api.github.com/search/repositories?q=${query}&sort=stars&order=desc`; const request = axios.get(githubApi); return (dispatch) => { request.then(({ data: dataFromGithub }) => { dispatch({ type: SEARCH_TERM, payload: query }); dispatch({ type: SAVE_SEARCH, payloadOne: query, payloadTwo:

How to use Redux-Thunk with Redux Toolkit's createSlice?

心已入冬 提交于 2021-02-04 12:08:26
问题 ==================== TLDR ========================== @markerikson (see accepted answer) kindly pointed towards a current solution and a future solution. EDIT: 15th Nov 2020: Link to Docs to use an Async Thunk in Slice RTK does support thunks in reducers using the thunk middleware (see answer). In 1.3.0 release ( currently alpha in Feb 2020 ), there is a helper method createAsyncThunk() createAsyncThunk that will provide some useful functionality (i.e. triggers 3 'extended' reducers dependent

How to use Redux-Thunk with Redux Toolkit's createSlice?

為{幸葍}努か 提交于 2021-02-04 12:08:13
问题 ==================== TLDR ========================== @markerikson (see accepted answer) kindly pointed towards a current solution and a future solution. EDIT: 15th Nov 2020: Link to Docs to use an Async Thunk in Slice RTK does support thunks in reducers using the thunk middleware (see answer). In 1.3.0 release ( currently alpha in Feb 2020 ), there is a helper method createAsyncThunk() createAsyncThunk that will provide some useful functionality (i.e. triggers 3 'extended' reducers dependent

How to use Redux-Thunk with Redux Toolkit's createSlice?

流过昼夜 提交于 2021-02-04 12:08:11
问题 ==================== TLDR ========================== @markerikson (see accepted answer) kindly pointed towards a current solution and a future solution. EDIT: 15th Nov 2020: Link to Docs to use an Async Thunk in Slice RTK does support thunks in reducers using the thunk middleware (see answer). In 1.3.0 release ( currently alpha in Feb 2020 ), there is a helper method createAsyncThunk() createAsyncThunk that will provide some useful functionality (i.e. triggers 3 'extended' reducers dependent

How to use Redux-Thunk with Redux Toolkit's createSlice?

£可爱£侵袭症+ 提交于 2021-02-04 12:07:52
问题 ==================== TLDR ========================== @markerikson (see accepted answer) kindly pointed towards a current solution and a future solution. EDIT: 15th Nov 2020: Link to Docs to use an Async Thunk in Slice RTK does support thunks in reducers using the thunk middleware (see answer). In 1.3.0 release ( currently alpha in Feb 2020 ), there is a helper method createAsyncThunk() createAsyncThunk that will provide some useful functionality (i.e. triggers 3 'extended' reducers dependent

How to use Redux-Thunk with Redux Toolkit's createSlice?

落花浮王杯 提交于 2021-02-04 12:07:36
问题 ==================== TLDR ========================== @markerikson (see accepted answer) kindly pointed towards a current solution and a future solution. EDIT: 15th Nov 2020: Link to Docs to use an Async Thunk in Slice RTK does support thunks in reducers using the thunk middleware (see answer). In 1.3.0 release ( currently alpha in Feb 2020 ), there is a helper method createAsyncThunk() createAsyncThunk that will provide some useful functionality (i.e. triggers 3 'extended' reducers dependent

TypeScript type of an async dispatch value

妖精的绣舞 提交于 2021-01-29 07:20:28
问题 I have the following async action definition: import {Dispatch} from 'react'; import axios, {AxiosResponse, AxiosError} from 'axios'; function asyncAction() { return (dispatch: Dispatch<any>): Promise<number> => { return axios.get('http://www.example.com') .then( (res: AxiosResponse<any>) => { return 1; }) .catch( (err: AxiosError<any>) => { return 2; }); } } The above typechecks fine. I also understand that when you call dispatch and pass it an asynchronous action, like so: dispatch

How to work with API call action in redux?

不羁岁月 提交于 2021-01-29 03:23:37
问题 I am new to redux and I am trying to make it work with my application, but I have problems with understanding how to work with async actions in it. I have action that is api call. This action should be called as soon as my other state is not empty. I do not get any mistakes but do not think that my action is called since the data is empty. Can anybody help to understand what I am doing wrong? Here is my actions.js. The wordsFetchData is the action I need to call: export function