Allow passing through a 'reason' from useBlocker
#14748
Huulivoide
started this conversation in
Proposals
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
What: Add a way to return a custom value from(through)
useBlockerWhat the possible public API could look like
Why?: Current API is limited when there are multiple blocking elements.
Current API is sufficient for simple scenarios where there is only a single form on the screen at once and the actual
useBlockercall can be inlined close to the blocking element and the reaction to changes in theBlockerresult can be specific to that call site.But sometimes there could be multiple elements/reason on the screen that could call for blocking of the navigation. As the current API already accpets a function as the
shouldBlockinput arg, it is possible to construct a compound blocker that can check for multiple reasons.That can work, but it has limitations on what can be shown in the
NavigationBlockedModalcomponent. That has to stay generic enough that any reason within the scope can apply to it, which puts limitations on how the actual content can be worder.In my current project the original use case for implementing such a compound blocker was that we had multiple views of high complexity entities where the displaying & editing of details was split onto multiple subsections in view. It was then possible to open any number of those subsections for editing simultaneously, thus creating multiple forms that could block the navigation. As in all cases it were forms that caused the blocking a generic "You have unsaved changes on one or more active forms on the page. Are you sure you want to discard your changes?" -modal was sufficient.
But recently a need has arisen to block the navigation on more variety of situations, for which the message should preferably be worded differently. While "It seems you might have unsaved edits on one or more of the form on the page, or maybe you did not finish downloading a report you were preparing? Are you sure want to discard all unfinished work?" -message is functional, it is not particularly good from the enduser's point of view.
Thus, if it were possible to return some sort of value from the
BlockerFunctionand then later read that back from the returnedBlockerobject, it would be easy to create a situation specific BlockerModal with informative conten in usecases that call for a compund-blocker.Related topic: Allow multiple blockers to exist simultaneously.
Beta Was this translation helpful? Give feedback.
All reactions