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

Allow message parameter of useBeforeUnload to be a function #1332

Closed
thdk opened this issue Jul 1, 2020 · 2 comments
Closed

Allow message parameter of useBeforeUnload to be a function #1332

thdk opened this issue Jul 1, 2020 · 2 comments

Comments

@thdk
Copy link

thdk commented Jul 1, 2020

Is your feature request related to a problem? Please describe.
The hook useBeforeUnload registers an event when a component that uses that hooks is rendered for the first time. The isDirty parameter can be a function but the message parameter currently is not. So the message is set once unless you rerender the component.

Describe the solution you'd like
I would like to suggest the following signature for useBeforeUnload

const useBeforeUnload = (
	enabled: boolean | (() => boolean) = true,
	message?: string | (() => string)
) => {
...
}

Describe alternatives you've considered
I've used a local state const [beforeUnloadMessage, setBeforeUnloadMessage] = useState(defaultMessage); but this caused the component to rerender only to display a different beforeUnloadMessage in case the user would navigate away.

I can send you a PR for this.

Related to #842

@kachkaev
Copy link
Contributor

kachkaev commented Dec 1, 2020

Given that custom message is no longer supported by most browsers, should we just mark the message arg as @deprecated instead? Supporting function value and even asking the devs to provide any value does not seem worthy these days. The result won’t be seen by most users anyway.

Somewhat related PR: #1673

@thdk
Copy link
Author

thdk commented Dec 2, 2020

That's indeed what I've also discovered after logging this issue.

Closing this in favor of #1673

@thdk thdk closed this as completed Dec 2, 2020
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

2 participants