redux

axios catch doesn't catch error

会有一股神秘感。 提交于 2020-05-30 07:56:31
问题 I'm using axios 0.17.0 with the following code: this.props.userSignupRequest(this.state) .then( res => { console.log(res.data) } ) .catch( err => { this.setState({ errors: err.response }) } ) And the server is set to return a 400 when user signup validation doesn't pass. That also shows up in console: POST 400 (Bad Request) , but the setState is not being executed. Why is that? I also tried console.log(err) and nothing. 回答1: A few issues could be at play, we'll likely need to see more of your

Uncaught TypeError: Cannot read property 'main' of undefined when trying to use React MuiAlert

两盒软妹~` 提交于 2020-05-29 08:30:22
问题 I am trying to build a Redux based notificator based on this example: https://material-ui.com/components/snackbars/#CustomizedSnackbars.tsx And here is what I came up with: import { Snackbar } from '@material-ui/core'; import MuiAlert, { AlertProps } from '@material-ui/lab/Alert'; import React from 'react'; import { connect } from 'react-redux'; import { createSelector } from 'reselect'; import { ProgramCategoryActions } from '../../program/store/program-category.actions'; import {

Should Actions in Redux always be unique?

荒凉一梦 提交于 2020-05-28 14:17:52
问题 In this example I'm using an action named ADD_TODO import { createStore, combineReducers } from 'redux'; function todos(state, action) { state = state || []; switch (action.type) { case 'ADD_TODO': return state.concat([ action.text ]); default: return state; } } function counter(state, action){ state = state || 0; switch (action.type){ case 'INCREMENT': return state+1; case 'DECREMENT': return state-1; case 'ADD_TODO': return state+100; default: return state; } } var app = combineReducers({

react native. the close event of the application

断了今生、忘了曾经 提交于 2020-05-26 09:34:25
问题 On one of the pages of the developed application for ios on react native there is a switch components. When interacting with them, the state of the switches is stored in the Redux storage, but when leaving the page or leaving the application, you need to send the state data to the server. Leaving the page is implemented as follows: props.navigation.addListener('willBlur', async() => { props.pushDataOnServer(data, token); }); We add a navigation handler (StackNavigator) for the willBlur event,

Expected to return a value at the end of arrow function

梦想与她 提交于 2020-05-24 11:18:40
问题 Everything works fine, but i have this warning Expected to return a value at the end of arrow function array-callback-return , i try use forEach instead map , but then <CommentItem /> doesn't even show. How fix it? return this.props.comments.map((comment) => { if (comment.hasComments === true) { return ( <div key={comment.id}> <CommentItem className="MainComment"/> {this.props.comments.map(commentReply => { if (commentReply.replyTo === comment.id) { return ( <CommentItem className="SubComment

How to fix Parsing error: Can not use keyword 'await' outside an async function

有些话、适合烂在心里 提交于 2020-05-24 07:32:48
问题 Getting a error message saying Parsing error: Can not use keyword 'await' outside an async function from below code for Redux action. What is the proper way to write this? export async function getData() { return (dispatch) => { try { const data = await API.graphql(graphqlOperation(query)) dispatch({ type: "DATA_AVAILABLE", data: data.data.listData.items }); } catch(err) { console.log('error: ', err) } } } 回答1: You need to have async keyword for the inner function export function getData() {

redux form server side validation

生来就可爱ヽ(ⅴ<●) 提交于 2020-05-17 08:24:32
问题 I am stuck in setting the server-side validation of the redux form. I have a registration form and performing a client-side validation perfectly, but while in server-side validation I am unable to understand how to display the error message from the server with a respective input field. API request const createMemberRegistration = user => { return dispatch => { dispatch({ type: POST_REQUEST }); processMemberRegistration(user) .then(user => { dispatch({ type: REGISTRATION_SUCCESS }); dispatch

redux form server side validation

ぐ巨炮叔叔 提交于 2020-05-17 08:23:46
问题 I am stuck in setting the server-side validation of the redux form. I have a registration form and performing a client-side validation perfectly, but while in server-side validation I am unable to understand how to display the error message from the server with a respective input field. API request const createMemberRegistration = user => { return dispatch => { dispatch({ type: POST_REQUEST }); processMemberRegistration(user) .then(user => { dispatch({ type: REGISTRATION_SUCCESS }); dispatch

React, Redux - redirect after object is created (using new object id in URL)

末鹿安然 提交于 2020-05-17 07:15:20
问题 I think I have a quite common problem, but can't find up to date answer that I would be sure is good practice. I'm writing a forum app using React, Redux, React Router DOM. I'm using BrowserRouter. Here is what I want to do: after I post a request to create a thread and it is fulfilled, I want to redirect user to newly created thread page (I need object id that I will get in response for URL). component class CreateThread extends React.Component { handleCreateThread = (values) => { this.props

How to render a value recived in mapStateToProps (REDUX)

风格不统一 提交于 2020-05-17 07:02:23
问题 I am using reduce to store a value and then give it back. I am receiving it correcty but how to render automaticaly when is received? The code of the code of mapStateToProps: import React, { Component } from "react"; import { Tabs, Tag } from 'antd'; import { connect } from "react-redux"; import SelecionarCrypto from "./SelecionarCrypto"; import TableData from "./TableData"; import axios from "axios"; import moment from "moment"; const { TabPane } = Tabs; class PruebasAPI3 extends Component {