Skip to content
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

[v6] [Feature]: usePrompt() should have callback to check 'desired' path before warning #7926

Closed
onionhammer opened this issue Jul 29, 2021 · 7 comments

Comments

@onionhammer
Copy link

What is the new or updated feature that you are suggesting?

Currently usePrompt gives no way to not show the prompt if the user is simply navigating to another path in the same area where a warning wouldnt necessarily be needed or wanted.. for example, if I have 3 tabs on the same page in the same form, navigating between tabs does not clear the state (the user loses no data), but if they navigate out a level ('..') they would lose state.

It would be great to be able to check the 'next' path that the user is trying to go to to decide if they should be prompted.

function usePrompt(message: string, when?: boolean | (to: To) => boolean): void

Why should this feature be included?

This would allow users to change to SOME paths without prompting, but but prompt instead when users are fully leaving an area of your application

@timdorr
Copy link
Member

timdorr commented Jul 29, 2021

That's what the to argument is on the function version of the when parameter. It represents the next location you're going to.

@timdorr timdorr closed this as completed Jul 29, 2021
@onionhammer
Copy link
Author

onionhammer commented Jul 29, 2021

@timdorr that's the proposed function signature, not the current signature, which is:

function usePrompt(message: string, when?: boolean): void

@timdorr
Copy link
Member

timdorr commented Jul 29, 2021

Sorry, wasn't paying attention...

@timdorr timdorr reopened this Jul 29, 2021
@philals
Copy link

philals commented Aug 17, 2021

Hi. Where are the docs for usePrompt? I cannot find it in the repo or on the dev branch. Thanks

Edit: Found it! GitHub search was not finding it

https://github.com/remix-run/react-router/blob/dev/packages/react-router-dom/index.tsx#L321

@onionhammer
Copy link
Author

onionhammer commented Aug 17, 2021

@philals I've only been using this blog post as a reference:

https://reacttraining.com/blog/react-router-v6-pre/

@chaance chaance changed the title [Feature]: usePrompt() should have callback to check 'desired' path before warning [v6] [Feature]: usePrompt() should have callback to check 'desired' path before warning Sep 4, 2021
@timdorr
Copy link
Member

timdorr commented Dec 10, 2021

Closing since this API is no longer in the library. #8139 will track when it's added back.

@timdorr timdorr closed this as completed Dec 10, 2021
@uthbees
Copy link

uthbees commented Mar 14, 2023

usePrompt was added back in #9932, any chance this can be reopened?

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

No branches or pull requests

4 participants