usePrompt
Wrapper around useBlocker to show a window.confirm prompt to users instead of building a custom UI with useBlocker.
Parameters
The message to show in the browser’s confirmation dialog when navigation is blocked.
A boolean or a function that returns a boolean indicating whether to block the navigation.If a function is provided, it receives an object with:
currentLocation- The current locationnextLocation- The location being navigated tohistoryAction- The type of navigation (“PUSH”, “REPLACE”, or “POP”)
Type Declaration
Deprecation Notice
Theunstable_ flag will not be removed because this technique has a lot of rough edges and behaves very differently (and incorrectly sometimes) across browsers if users click additional back/forward navigations while the confirmation is open.
Use useBlocker instead for more reliable and customizable navigation blocking.
Migration to useBlocker
Before (using usePrompt)
After (using useBlocker)
Usage Examples (Legacy)
Basic Usage
Conditional Blocking
With Form State
Multiple Conditions
Known Issues
Browser Inconsistencies
- Multiple back/forward clicks: If users click back/forward multiple times while the prompt is open, behavior varies across browsers
- Mobile browsers: May not show the confirmation dialog reliably
- Browser dialogs: Cannot be styled or customized (uses native
window.confirm)
Limitations
Why It’s Deprecated
- Unreliable: Browser behavior varies, especially with rapid navigation
- Poor UX: Native browser dialogs cannot be styled or customized
- Better alternative:
useBlockerprovides full control over the blocking experience - Accessibility: Custom dialogs via
useBlockercan be made more accessible
Recommended Alternative
UseuseBlocker for better control and reliability:
Notes
- Deprecated: Use
useBlockerinstead - Available in Framework and Data modes only
- Only blocks in-app navigation (not page reloads or tab closes)
- Use
useBeforeUnloadto warn about page reloads/closes - Cannot customize the appearance of the browser’s confirmation dialog
- Behavior is inconsistent across browsers
Related
useBlocker- Recommended replacement with custom UIuseBeforeUnload- Warn before page reload/close- Navigation Blocking Guide - Learn about blocking navigation