redux-thunk

Passing initial state from API call to createStore when react native application boots up

喜你入骨 提交于 2020-01-24 14:22:27
问题 I am having trouble initialising my redux-state when my react-native application boots up. I need to make an api call before the application boots up to retrieve data to hydrate my state. Id like to pass the result of this call to the createStore function in my Provider JSX element. I have read different things about how to do that but none of them seems to work. Here's my root App component : import React, { Component } from 'react'; import { View } from 'react-native'; import { Provider }

Passing initial state from API call to createStore when react native application boots up

末鹿安然 提交于 2020-01-24 14:21:26
问题 I am having trouble initialising my redux-state when my react-native application boots up. I need to make an api call before the application boots up to retrieve data to hydrate my state. Id like to pass the result of this call to the createStore function in my Provider JSX element. I have read different things about how to do that but none of them seems to work. Here's my root App component : import React, { Component } from 'react'; import { View } from 'react-native'; import { Provider }

Actions must be plain object. Use custom middleware

冷暖自知 提交于 2020-01-21 11:44:46
问题 I am using Redux,redux-thunk with react. I am returning an object but still getting the error. authActions.js export function register(){ return (dispatch)=>{ console.log("in register action"); dispatch({type:'auth_user'}) } } calling this action from Register.js using connect and props import * as actions from '../actions/authActions'; class RegisterForm extends React.Component{ handleRegister = (e)=>{ e.preventDefault(); console.log("inside handle register"); console.log(this.props); this

Actions must be plain object. Use custom middleware

白昼怎懂夜的黑 提交于 2020-01-21 11:44:08
问题 I am using Redux,redux-thunk with react. I am returning an object but still getting the error. authActions.js export function register(){ return (dispatch)=>{ console.log("in register action"); dispatch({type:'auth_user'}) } } calling this action from Register.js using connect and props import * as actions from '../actions/authActions'; class RegisterForm extends React.Component{ handleRegister = (e)=>{ e.preventDefault(); console.log("inside handle register"); console.log(this.props); this

How does middleware execute async actions?

 ̄綄美尐妖づ 提交于 2020-01-05 07:12:43
问题 I am having a little difficulty understanding how Redux-Thunk (or other middleware) execute async actions. From below example, I can see that when onOrder is called (maybe via a click event), it will dispatch the action created by purchaseBurger . purchaseBurger in turn return a function that will dispatch an action indicating purchase started, followed by an http request. My confusion is: When does that function returned by purchaseBurger actually gets called and executed? How does it get

React-Redux-Thunk: actions does not return dispatch

笑着哭i 提交于 2020-01-05 07:05:49
问题 I am using React Native with Redux-thunk middleware. My problem is dispatch function does not return the object and does not even console. Here is my actions file: function movieSelc(movie) { return { type: types.MOVIE_SELECT, selectedMovie: movie }; } export function selectMovie(m) { console.log("this console works!") return (dispatch) => { console.log("this console never works") dispatch(movieSelc(m)); }; } This is the component(i am not including here const styles to make it a bit shorter)

redux dispatch fires multiple times

守給你的承諾、 提交于 2020-01-03 18:38:27
问题 I'm experiencing following unwanted behaviour in Redux (React/ Redux + redux-thunk): I'm triggering an event (click) wich lets an action fire and dispatch some additional data as objects in an array. When I'm clicking the first time the action dispatches once with one object in the array (result 1: one new object) - and that's fine. But now the unwanted thing happens: When I'm clicking the second time calling for new additional data the action dispatches twice - first time with the formerly

redux dispatch fires multiple times

只谈情不闲聊 提交于 2020-01-03 18:37:06
问题 I'm experiencing following unwanted behaviour in Redux (React/ Redux + redux-thunk): I'm triggering an event (click) wich lets an action fire and dispatch some additional data as objects in an array. When I'm clicking the first time the action dispatches once with one object in the array (result 1: one new object) - and that's fine. But now the unwanted thing happens: When I'm clicking the second time calling for new additional data the action dispatches twice - first time with the formerly

React/Redux store state is not saved

≯℡__Kan透↙ 提交于 2020-01-01 15:57:33
问题 I use thunk middleware and pass initial state to React, but the problem is that React state is not saved when I visit other links. After successfully logged in, it's supposed to render dashboard. User must be redirected to dashboard(which is the root path, / ) when he tries to go to /login page. Should i use redux-router too? I omitted some of code, but it almost looks like below. init.js I passed store to Provider import { Provider } from 'react-redux'; import configureStore from './store

React/Redux store state is not saved

∥☆過路亽.° 提交于 2020-01-01 15:56:03
问题 I use thunk middleware and pass initial state to React, but the problem is that React state is not saved when I visit other links. After successfully logged in, it's supposed to render dashboard. User must be redirected to dashboard(which is the root path, / ) when he tries to go to /login page. Should i use redux-router too? I omitted some of code, but it almost looks like below. init.js I passed store to Provider import { Provider } from 'react-redux'; import configureStore from './store