Reputation: 843
can I use redux thunk and manage catch error in component?, is recommended ?
const handleSubmit = (values) => {
try {
await dispatch(postLogin(values));
} catch (err) {
setError(true);
}
}
or I should run dispatch in catch of the actionCreator ?
Thanks.
Upvotes: 0
Views: 910
Reputation: 681
If the error is caught, you could dispatch an action object instead of logging it or calling another handler. It helps, in case you want to display the error message anywhere in your component.
const handleSubmit = (values) => {
try {
await dispatch(postLogin(values));
} catch (err) {
dispatch({
type: LOGIN_ERROR,
payload: { err }
})
}
}
Upvotes: 1