react-thunk

BrowserRouter vs Router with history.push()

半城伤御伤魂 提交于 2020-06-09 16:46:00
问题 I am trying to understand the difference between BrowserRouter and Router of the react-router-dom (v5) package and what difference it makes for my example below. The documentation says: BrowserRouter A that uses the HTML5 history API (pushState, replaceState and the popstate event) to keep your UI in sync with the URL. Source: https://reacttraining.com/react-router/web/api/BrowserRouter Router The common low-level interface for all router components. Typically apps will use one of the high

BrowserRouter vs Router with history.push()

南笙酒味 提交于 2020-06-09 16:45:57
问题 I am trying to understand the difference between BrowserRouter and Router of the react-router-dom (v5) package and what difference it makes for my example below. The documentation says: BrowserRouter A that uses the HTML5 history API (pushState, replaceState and the popstate event) to keep your UI in sync with the URL. Source: https://reacttraining.com/react-router/web/api/BrowserRouter Router The common low-level interface for all router components. Typically apps will use one of the high

BrowserRouter vs Router with history.push()

谁说胖子不能爱 提交于 2020-06-09 16:42:46
问题 I am trying to understand the difference between BrowserRouter and Router of the react-router-dom (v5) package and what difference it makes for my example below. The documentation says: BrowserRouter A that uses the HTML5 history API (pushState, replaceState and the popstate event) to keep your UI in sync with the URL. Source: https://reacttraining.com/react-router/web/api/BrowserRouter Router The common low-level interface for all router components. Typically apps will use one of the high

NaN problem with react-redux and react-thunk

余生颓废 提交于 2020-03-23 12:01:38
问题 I'm trying to get data from api about currencies and I get error about NaN. I console.log(this.props) There it is: There is what I already did. In my actionTypes.js export const FETCH_DATA_BEGIN = 'FETCH_DATA_BEGIN'; export const FETCH_DATA_SUCCESS = 'FETCH_DATA_SUCCESS'; export const FETCH_DATA_FAIL = 'FETCH_DATA_FAIL'; and also there is my action.js export const fetchData = () => { return dispatch => { fetch(`https://api.exchangeratesapi.io/latest?base=${this.props.base}`) .then(res => res

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 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

Async initial state React-Redux Redux-Thunk

廉价感情. 提交于 2019-12-23 07:03:23
问题 Using React , Redux , Redux-thunk I want to have an initial state through a server request (API call) but I cannot seem to get this to work. What I have got so far: var Redux = require('redux'); var carReducer = require('./reducers/cars'); var thunk = require('redux-thunk').default; var initialState = require('./reducers/initialState'); var rootReducer = Redux.combineReducers({ cars: carReducer }); module.exports = Redux.applyMiddleware(thunk)(Redux.createStore)(rootReducer, initialState

Redux - how to call an action and wait until it is resolved

强颜欢笑 提交于 2019-12-07 12:04:16
问题 I'm using react native + redux + redux-thunk I do not have much experience with redux and react native I'm calling an action inside my component. this.props.checkClient(cliente); if(this.props.clienteIsValid){ ... } and within that action there is a call to an api that takes a few seconds. export const checkClient = (cliente) => { return dispatch => { axios.get(`${API_HOST}/api/checkclient`, header).then(response => { dispatch({type: CHECK_CLIENT, payload: response.data }); //valid or invalid