-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: useBlocker is not working #11385
Comments
You may have a stale closure problem - try using the value directly or using a callback with dependencies: // Direct
let blocker = useBlocker(show);
// Callback
const whenToBlock = React.useCallback(() => show, [show]);
let blocker = useBlocker(whenToBlock); Or, you my need to wait for the react state to flush out after dispatching your action. It's hard to say without a working reproduction. |
I can confirm this as well |
I don't think this is the issue. I have tried this no difference. |
Could either of you provide a minimal reproduction? |
This issue has been automatically closed because we haven't received a response from the original author 🙈. This automation helps keep the issue tracker clean from issues that aren't actionable. Please reach out if you have more information for us! 🙂 |
What version of React Router are you using?
"react-router-dom": "^6.22.3",
Steps to Reproduce
Create some routes with createBrowserRouter().
Create a Modal which shows something.
Example code
onClick={() => {
dispatch(CHANGE_MODAL_STATE({ show: false, type: null }));
console.log("blocker", blocker);
blocker.proceed();
}}
{
location: undefined
proceed: undefined
reset: undefined
state: "unblocked"
}
The text was updated successfully, but these errors were encountered: