redux

How to pass an image to the backend from react and redux

只谈情不闲聊 提交于 2020-07-06 04:27:45
问题 I'm using the MERN stack and I want to be able to upload an image in the front end (react) and access it in the backend (express, nodejs) to store it later. I'm using multer but I keep getting undefinied when I try to console.log() the req.file object. frontend: import React, { Component } from "react"; import { Link, withRouter } from "react-router-dom"; import { connect } from "react-redux"; import PropTypes from "prop-types"; import { addPlayer } from "../../actions/profileActions"; class

Promises in redux-saga

早过忘川 提交于 2020-07-05 07:02:51
问题 I found the same question here, but without a proper answer I am looking for. I am developing a simple application with CRUD operations. On the edit page, after the component gets mounted ( componentDidMount() ), the app dispatches an action to retrieve a specific post details: dispatch({ type: FETCH_POST, id: 'post-id' }) I am using redux-saga and want the above call to return a Promise so that I can access the API response. Right now, without a callback/Promise, I ended up with defining a

How to force redux dispatch to finish first before doing a next action?

最后都变了- 提交于 2020-06-29 05:10:23
问题 Hello guys im facing an issue with redux , it seems that wrapping it with a promise does not ensure that the async functions run finish first . Here's some of my code: apiGet(){ // where my dispatch function lives at var getstates = this.props.get_states(this.props.match.params.id) var gettransitions = this.props.get_transitions(this.props.match.params.id) var workflowclass_fetcher = this.props.get_workflow(this.props.match.params.id) Promise.all([getstates, gettransitions , workflowclass

Redux - Angular: How prevent actions called twice?

空扰寡人 提交于 2020-06-29 04:33:14
问题 Redux It's a very cool library, I really like it, but how can I prevent that actions call twice? What mistakes can generate this behavior ? Consider that I've already unsubscribe the subscription into the controller constructor(private _store: Store<AppState>) { this.subscription = this._store.select('reduxObj').subscribe(function (item) { switch (item.type) { case fromAction.GETITEMS: { break; } } }.bind(this)); } ngOnDestroy() { this.subscription.unsubscribe(); } ngOnInit() { this._store

Why is dispatch() causing redirect to initialRouteName in react-navigation?

倾然丶 夕夏残阳落幕 提交于 2020-06-29 04:30:32
问题 I'm having a problem where every dispatch causes the navigator to redirect to my initialRouteName . Because of my componentDidUpdate methods, I eventually land on the correct screen, but only in some cases. I have used ReactNavigation several times before without any problems. The only thing that stands out is that <NavigationContainer onStateChange is getting called once for all dispatch'd action, not just those under the navigator reducer. Is that normal? root.js import 'react-native

React Saga Yield call does not finish before next code is run

回眸只為那壹抹淺笑 提交于 2020-06-29 04:06:13
问题 I have a react saga code here which does not run in sequence: yield put({ type: 'SHOW_LOADER', loading: 'workflowobject' }) #yield to initiate the loader const states = yield call(() => axiosInstance.get(`/workflow-object/state/list/${action.workflow_id}/${action.workflow_object_id}/`)) const newState = states.data.map(item => ({ // some operation to shape my data , might this be the issue? iteration: item.iteration, ...item.state })); yield put({ type: "STORE_WORKFLOW_DATA", payload:

How to fetch data over multiple pages?

帅比萌擦擦* 提交于 2020-06-28 03:49:11
问题 My project is based on React, redux, redux-saga, es6 and I try to fetch data from this API: http://api.dhsprogram.com/rest/dhs/data/BD,2000,2004,2007?&returnFields=CharacteristicLabel,Indicator,IndicatorId,Value&f=json As you can see, this specific API call shows data with a limit of 100 data per page spread on 40 pages. According to this answer: http://userforum.dhsprogram.com/index.php?t=msg&th=2086&goto=9591&S=Google it says that you can extend the limit to a maximum of 3000data per page.

React get state from Redux store within useEffect

五迷三道 提交于 2020-06-27 16:54:51
问题 What is the correct way to get state from the Redux store within the useEffect hook? useEffect(() => { const user = useSelector(state => state.user); }); I am attempting to get the current state within useEffect but I cannot use the useSelector call because this results in an error stating: Invariant Violation: Hooks can only be called inside the body of a function component. I think I understand why as it breaks one of the primary rules of hooks. From reviewing the example on the Redux docs

How to create a custom equality function with reselect and Typescript?

a 夏天 提交于 2020-06-27 16:22:13
问题 A standard reselect selector invalidates its memoized value and recomputes it if the input selectors fail a strict equality check: export const selectEmailsFromComments = createSelector( selectComments, // returns an array of comments comments => commentsToEmails(comments) ) Since the comments are an array and not a primitive value, and redux reducers tend to create a new piece of state to avoid side effects, the above seems to never actually memoize because the comments array returned by

Why Typescript throw error message: Property does not exist on type?

杀马特。学长 韩版系。学妹 提交于 2020-06-27 13:39:05
问题 I created two code examples. The only difference between them is what expression I pass to the switch operator. In a first case I use an object property. And it works fine. In a second case I create a type variable. And Typescript throw an error message: Property 'name' does not exist on type 'Action'. Property 'name' does not exist on type '{ type: "reset"; }'. Why is this happening? The object property action.type and variable type are of the same type 'reset' | 'update' . interface State {