Skip to content

Conversation

@uhyo
Copy link
Owner

@uhyo uhyo commented Dec 27, 2025

Add useBlocker hook to prevent navigation away from the current route.
This is useful for scenarios like unsaved form data or ongoing uploads.

  • Add BlockerContext and registry for managing multiple blockers
  • Integrate blocker checks into NavigationAPIAdapter
  • Use ref pattern to avoid stale closure issues
  • Add comprehensive tests for various blocking scenarios
  • Update documentation with usage examples

The hook supports:

  • Multiple blockers in the component tree (any true blocks)
  • Dynamic blocking based on component state
  • Calling confirm() inside the callback for user prompts
  • Proper cleanup on unmount

Add useBlocker hook to prevent navigation away from the current route.
This is useful for scenarios like unsaved form data or ongoing uploads.

- Add BlockerContext and registry for managing multiple blockers
- Integrate blocker checks into NavigationAPIAdapter
- Use ref pattern to avoid stale closure issues
- Add comprehensive tests for various blocking scenarios
- Update documentation with usage examples

The hook supports:
- Multiple blockers in the component tree (any true blocks)
- Dynamic blocking based on component state
- Calling confirm() inside the callback for user prompts
- Proper cleanup on unmount
- Change signature from useBlocker(fn) to useBlocker({ shouldBlock })
- Remove ref pattern, fix stale closure via useCallback in tests/docs
- Export UseBlockerOptions type
@uhyo uhyo merged commit b4751e4 into master Dec 27, 2025
1 check passed
@uhyo uhyo deleted the claude/implement-useBlocker-hook-dy8Bc branch December 27, 2025 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants