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

Caution about navigator callbacks in functional components is confusing #3580

Open
3 of 8 tasks
EndilWayfare opened this issue Jan 5, 2024 · 0 comments
Open
3 of 8 tasks

Comments

@EndilWayfare
Copy link
Contributor

This is about:

  • A typo
  • Innaccurate/misleading documentation (e.g. technically incorrect advice)
  • Undocumented code
  • Outdated documentation
  • Other

Problem

https://yew.rs/docs/concepts/router#function-components

The example here uses Callback::from. Use a normal callback if the target route can be the same as the route the component is in, or just to play safe.

What is a "normal" Callback in this context? The quoted wording of the Caution suggests that it's something different than what's returned from Callback::from. But that's the normal-est Callback I can think of.

The Caution goes on to warn about a panic! that would be caused by a button on a page that goes back to the same page. I understand why the hook would not trigger a re-render in that case, but I don't understand why that would panic. I copy/pasted the code into a quick example, and it worked just fine.

Is this perhaps a vestige of CallbackOnce? That's the only thing I can imagine that would cause a panic, if you tried to call a FnOnce twice.

Details about the solution you'd like (Optional)

If this is out of date, and the caveat no longer applies, just removing the Caution should be sufficient.

If there still is something to watch out for, the wording should more explicitly describe the "good" and "bad" option and why the "bad" one will panic, ideally with example code that can be verified to, in fact, panic.

Additional context (Optional)

Questionaire (Optional)

  • I'd like to write this documentation
  • I'd like to write this documentation but I'm not sure what's needed
  • I don't have time to add this right now, but maybe later
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant