redux-thunk

How to access redux-store from within react's componentDIdMount()

人盡茶涼 提交于 2019-12-24 19:53:11
问题 In the following code I am trying to pass the state.userData.userDetails from the redux-store to getleftpaneProductCatalogue() , but state.userData.userDetails is unaccessible to componentDidMount() . I tried assigning the state.userData.userDetails to this.prop.userProfile , but still this.prop.userProfile is an empty value. How to access the prop within componentDidMount ? import React,{Component} from 'react'; import { connect } from 'react-redux'; import {Row, Col } from 'react

Why don't chaining dispatch Redux-Thunk

天大地大妈咪最大 提交于 2019-12-24 19:10:34
问题 Why don't chaining dispatch Redux Thunk? Only work first dispatch and second dispatch is not working. Store: const store = createStore(reducers, loadState(), applyMiddleware(thunk)); Action: export function doSomething(name) { return function (dispatch) { dispatch({ type: 'USERNAME', payload: name }) dispatch({ type: 'OTHER_TYPE', payload: 'text' }) return true; } } Edit It's worked: return Promise.all([ dispatch({ type: 'USERNAME', payload: name }), dispatch({ type: 'OTHER_TYPE', payload:

Redux-thunk: API response keeps pending

﹥>﹥吖頭↗ 提交于 2019-12-24 18:39:50
问题 I am trying to develop an application, that is showing photos from Unsplash given a keyword. I managed to fetch specific photos using unsplash.js. In my actions, I have several action creators: export const fetchPhotos = () => ({ type: FETCH_PHOTOS }); export const receivePhotos = term => { const unsplash = new Unsplash({ applicationId: "id", secret: "secret", callbackUrl: "callback" }); console.log(term); const response = unsplash.search .photos(term, 1, 20) .then(toJson) .then(json => json)

Redux thunk in react native

风格不统一 提交于 2019-12-24 11:31:00
问题 I'm getting and error on createStor that I'm not understanding why import { createStore, applyMiddleware, combineReducers, compose } from 'redux'; import thunk from "redux-thunk" import promise from "redux-promise-middleware" import * as reducers from './reducers'; const middleware = applyMiddleware(promise(), thunk); export default createStore(reducers, middleware); Above is my code and I get the error in the line const middleware = applyMiddleware(promise(), thunk); The error is Expected

Handling Catch in Thunk Action with async/await

陌路散爱 提交于 2019-12-24 10:57:49
问题 Having trouble figuring out how to handle exceptions here. Container async handleResetPassword(uuid) { console.log("handleResetPassword invoked!") try { await this.props.resetUserPassword() ...rest of the code Thunk Action export function resetPasssord() { return async (dispatch, getState) => { const state = getState() try { const response = await UserApi.ResetUserPassword(state.auth.token) if(response && response.body){ dispatch(UserActions.resetPasswordReceived) } dispatch(UserActions

Redux state not being updated after dispatched actions

删除回忆录丶 提交于 2019-12-24 10:48:48
问题 My redux state is not being properly updated after actions are dispatched. I am using redux and redux-thunk to make calls to an API and save it into a redux store. My state is supposed to hold a JSON file due to the fact that a lot of the JSON file will be used and it seems that none of the JSON file is being stored into the store. The problem is explained down at the bottom This is my types.js file that define the action types: export const FETCHING_REQUEST = "FETCHING_REQUEST"; export const

How to dispatch a thunk from a saga?

与世无争的帅哥 提交于 2019-12-23 14:02:24
问题 I know I shouldn't be trying to dispatch thunks from sagas, it goes against what redux-saga tries to do. But I'm working in a fairly large app and most of the code is made with thunks, we are migrating by bits and need to dispatch a thunk from inside a saga. The thunk can't be changed because it is used in other parts (a thunk that returns a promise), so it would break many things. configureStore: const store = createStore( rootReducer, initialState, compose(applyMiddleware(thunk,

redux-thunk: Pause Component Execution Until Action Creator Completes

筅森魡賤 提交于 2019-12-23 12:00:03
问题 I've been struggling with this problem for several weeks now. I'm finally throwing in the towel and asking for help on this because I'm clearly not doing something right. I have a React.js app that is using redux and redux-thunk. I'm simply trying to get my Component Container to initiate the loading of data, but not render until the data comes back from the fetch request. Seems simple enough I know. Here is what I've done: Container Component 'use strict'; import React, { Component } from

How do I resolve “Actions must be plain objects. Use custom middleware for async actions.]”?

会有一股神秘感。 提交于 2019-12-21 20:08:27
问题 So I have wasted 5 hours on this. I have a redux thunk action like this: export const fetchUser = () => async (getState, dispatch) => { if (getIsFetching(getState().user)) { return Promise.resolve(); } dispatch(fetchUserRequest()); try { const response = await api.fetchUser(); dispatch(fetchUserSuccess({ userObject: { ...response } })); } catch (error) { dispatch(fetchUserFailure({ message: "Could not fetch user profile." })); } }; Calling this always ended up in Actions must be plain objects

Redux store not connected

我怕爱的太早我们不能终老 提交于 2019-12-20 07:44:48
问题 I am developing a Reactjs web application from scratch and encountered a tricky situation which i need help with. Whenever i navigate away from a particular url and navigate back, my redux store does not seem to be connected. routes.js const RouteList = () => ( <main> <Switch> <Route path="/abc/" exact component={withRouter(HomePage)} /> <Route path="/abc/xyz" exact component={withRouter(XYZPage)} /> <Redirect from="/" to="/abc/" /> <Route component={Error} /> </Switch> </main> ); export