score:5
There is no straight forward way to do this, you basically have two options: set the error to undefined in the reducer when another action fires, or provide a close button on the error itself using a reusable error component, that dispatches an action that will set the error to undefined in the reducer.
Personally i've always used the first method, lets take the submit of a form as an example. When the user submits the form you fire form-submit/request
and maybe show a loading message. If the form is sent correctly you fire form-submit
and if an error happens you fire form-submit/error
, setting the error in the reducer. Then in form-submit/request
you clear the error, so the user gets feedback if an error happens but if the form is submitted again the error is cleared. If you don't want to do anything when the form is submitted, which is odd, you can clear the error when form-submit
is fired. The downside of this approach is that if for example you want to clear the error when any field of the form is changed, you'll have to add another action and make the error undefined for that action as well.
Now if you put a close button in the error component you can reuse the error React component, but you'll have to have a action/dismiss-error
action for every API call and set the error to undefined on the reducer for each one of them, this can get very tedious quickly.
The best approach for me is to use the first method, but choosing carefully how much errors you display for each page or section. This way each page can have its error section that will be displayed for any API call that is associated with the page and you only need an error action for each page, not for every API call.
score:1
A store holds the whole state tree of your application. The only way to change the state inside it is to dispatch an action on it.
That's it. If you keep something in redux state then to change it's value you have to dispatch an action.
Source: stackoverflow.com
Related Query
- How to clear error message coming from redux actions
- How to show Toast only once after received error message prop from Redux store
- How to show an error message to the user in React when no data coming from API
- What is this error coming from source-map-loader and how do I resolve it?
- How to find display error message from API in reactjs
- How to display custom error message from Node/Express in React/Redux?
- How to get error message in Redux toolkit?
- Redux Toolkit: Unable to get access to the error message sent from the server
- How to find out where the error is coming from in ReactJS?
- How to stop Redux RTK query from retrying on error
- How can I make a function Async in reactjs which calls another two functions from redux actions
- How to display error message from express backend to react frontend?
- Displaying error message from redux state
- How to pass my error message from server called by axios to my component
- How to get error message in terminal when using Redux React
- How do I retrieve the error message from an API request
- How can I show error message from API to the end-user?
- How to clear custom message created by error boundary when I navigate to other router pages
- React Redux SSR how to suppress initial actions called from componentDidMount?
- How catch error message from server nodejs?
- How do I send error message from server to client?
- How to display error message correctly from custom hook validation?
- react redux how to trigger container function with action coming from non react component
- How to show error message using PhoneInput from react-phone-input-2 package?
- How to map array response coming from the api using redux in react js in react js.?
- How do I stop nested React components that dispatch Redux actions which update state from getting stuck in an infinite loop?
- Redux react native: how to properly call multiple actions from different reducers
- How to get message property of an error returned from an express server
- How to unmount, unrender or remove a component, from itself in a React/Redux/Typescript notification message
- When to use native React.useReducer Hook and how it differentiate from Redux
More Query from same tag
- No routes matched location
- How to load data dynamically upon clicking second level?
- Caret position reverts to start of contenteditable span on re-render in React in Safari and Firefox
- Arrow function ambguity in ReactJS
- How to sort a nested array of objects in javascript?
- Updating state with setSate in array
- Dynamic props to child component reactjs
- How to create HTML opening and closing tab from a variable in React JS
- Paypal unsubscribe button gives CSP error
- Display data from jsonplaceholder api using react hooks
- reactjs: state properties are undefined after changing values
- React Router: Cannot read property 'pathname' of undefined
- why does react code for 'hello React' not working
- React: mutating state with ++
- RadioGroup will not select when onChange is set that uses useState hook
- What does spread operator outside of curly braces do?
- React functional component un-mounts/mounts the parent component after setting state
- React MaterialUI Button with RouterLink Component - how to pass Exact property?
- Managing React states correctly giving strange error
- multi filter mapping React Js
- Dynamically show information on a modal
- Reactjs closure when passing state to component
- react-router why does code continue executing after the transition?
- Link react versions between linked library and workspace application
- How to declare a type for react thunk in typescript and reuse for component dependency?
- Why isn't my new state hitting my component's render method?
- Redux-Promise not working
- TypeError: arrayObject.sort is not a function in react jest enzyme
- Get collection and its subCollection in firebase
- removing child component from parent component within map loop