useDispatch() causing unexpected navigate back to previous screen
useDispatch() causing unexpected navigation in React Native. After reloading the app it works. But when I create an action after a navigation flow it will not work.
What is the current behavior?
it backs me to the previous screen without any navigation
What is the expected behavior?
it will not me back
Which browser and OS are affected by this issue?
No response
Did this work in previous versions of React Redux?
- [ ] Yes
I'm afraid this doesn't have any useful information that we can help with, and the question seems confused to start with.
useDispatch is literally just return store.dispatch. It doesn't do anything by itself.
If you're talking about actually calling dispatch(someAction), that's going to trigger an update in your Redux store. What happens after that is up to your own app's reducer logic.
@markerikson without any reducer logic it goes back to my previous screen. but if I commented this code
dispatch({ type: appointmentAction.FETCH_APPOINTMENT_ATTACHMENTS, currentAttachment: response });//
it works fine.
// full code
const fetchData = async () => {
try {
setIsLoading(true);
const url = createURL(appointmentAction.FETCH_APPOINTMENT_ATTACHMENTS_URL, { appointmentId: selectedAppointmentId });
const response = await http.get(url);
dispatch({ type: appointmentAction.FETCH_APPOINTMENT_ATTACHMENTS, currentAttachment: response });
} catch (error) {
console.error('Error fetching data:', error);
} finally {
setIsLoading(false);
}
};
useEffect(() => {
fetchData();
}, []);
@khokanuzzman if dispatching an action is causing some kind of RN navigation behavior, that's because your own app code has to be set up to make that happen somehow. Whatever you're describing is not related to React-Redux because we're talking about a Redux store specifically, and it's not a bug in Redux because a Redux store is its own self-contained object and dispatching just triggers app code that is watching for state changes.