score:3
Accepted answer
one way to notify your component whether it was a success or a failure is to have your action return a promise. so your action would look like this:
export function addboard(data){
return function(dispatch){
return axios.post(`${api_url}/boards`,
{
name: data.name
}
)
.then(response => {
if(response.status === 201){
const result = response.data.result;
dispatch({ type: add_board_success, data: result });
return result;
}
});
}
}
then in your component you can do this:
addboard(formprops) {
this.props.addboard(formprops).then((result) => {
console.log("success!", result);
})
.catch(error => {
console.error(error);
});
}
you should probably also handle the catch
in your action, if you want to dispatch a add_board_fail
on an error, but then you'd have to rethrow that error if you still want to catch it in the component.
Source: stackoverflow.com
Related Query
- Checking if http is success or fail Reactjs
- How to redirect http to https for a reactJs SPA behind AWS Elb?
- Is there any way for ReactJS to send an HTTP request?
- How to do render only after http request completed in ReactJS
- spring security + oauth2 + reactjs + restful http client
- How to send HTTP headers in ReactJS using fetch()
- I fail to setState my ReactJS state dynamically with a function
- make http post request with reactJs and NodeJs
- setState in reactjs inside success function not setting state
- how to Make Http request from reactjs ?
- Meteor / ReactJS - UI blinking issue: rendering twice before and after checking a database
- How to get the HTTP request headers from initial page request in ReactJS
- Checking if data is posted in reactJS
- Having trouble checking if an array has data or is empty in ReactJS
- Trigger parent function on ajax success in reactjs
- Checking path link in Reactjs
- Checking multiple conditionals in reactjs
- Why does my ReactJS app throw a CORS error for http requests although they complete successfully in Postman app?
- How to make HTTP request to upload file from reactjs to google drive?
- Reactjs routing to home page after login success
- Yii2 and reactjs CORS filters gives Error: Response for preflight has invalid HTTP status code 401
- Problem when i using https call api to http in reactjs
- why axios convert http request to https in reactjs
- Download file from http response, using reactJS
- Display file upload message success or failure in reactjs
- 405 - http verb used to access this page is not allowed iis in reactjs app
- Checking if local storage has object inside in ReactJS
- How do I get reponse data from 400 http response in ReactJS
- checkbox reactjs is checking all options
- checking for first key in map with reactjs
More Query from same tag
- VSCode auto import - how to force Material-UI full path import
- react-router-dom possibility to have "oneof" params in one route
- Argument of type 'IAulasAdicionais[]' is not assignable to parameter of type 'string'
- Getting stale value of local state variable after response returned from promise
- Fetching Data from API using NextJS and Material UI React
- Spring Security httpBasic 404 for correct credentials
- npm linked local library requires node_modules while git linked libarary (same) doesn't
- React: How to prevent menu component from being remounted when switching pages
- Flow complaining about action union type in reducer
- Bulk loading items into React Context state with Typescript
- how to change usestate of state variable in if condition?
- changing background-color of a <tr> in react with useRef
- Protected router doesn't re-render when Redux state update
- Get the second element under mouse that isn't a parent of the first element
- How to change the filtered date format in material table react?
- Old state still exist even after updating state in react
- How do I use aysnc/await in this superagent call?
- How to get country code and Country name using IP in react js
- My firebase query call isn't getting my document even though it exists
- javascript addEventListener in react js component not working
- what does this useState function do and how?
- How can I recreate the layout in the example Using TailwindCSS?
- Fetching and displaying data with React
- Maximum call stack exceeded error in ReactJS. Can someone help explain what's going on? (Snippet on JSFiddle)
- Typing Redux Store with Typescript
- Browserify including entire module when only some parts used (react-addons)
- Why react is dispatching action works both sides?
- How can I change multiple Checkboxes in React Hook Form Via state
- styled-components not responding
- How can i extract react route pathname in the queryString url?