#4226·yew

`NodeRef` documentation is misleading about usage with `use_effect_with`

Author: sunjayCreated Sep 16, 2026Updated Sep 16, 2026
Labelsdocumentation

This is about:

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

Problem

This is a follow up to #4225. I closed that as a duplicate because I realized that the NodeRef behavior is intentional and other people have brought it up before, but after looking at the documentation more I think I was accidentally misled several times and that's what led to my misunderstanding.

Examples:

The docs for use_node_ref pass the node ref into use_effect_with:

https://github.com/yewstack/yew/blob/bfa6c19af971084f9547495388bde9aceeb81aaa/packages/yew/src/functional/hooks/use_ref.rs#L148-L153

There is even a tip that says:

https://github.com/yewstack/yew/blob/bfa6c19af971084f9547495388bde9aceeb81aaa/packages/yew/src/functional/hooks/use_ref.rs#L183-L187

This is misleading and is the exact example I used in #4225. If you conditionally render an element, its NodeRef::get method will return None until it is rendered the first time. Since NodeRef uses pointer equality for PartialEq, the effect will never run again after that even when NodeRef is eventually Some because the node was rendered.

The specific events example from #4225 and the buggy use_event hook in yew-hooks that I cite in that issue are both essentially just cleaned up versions of the "Manual event listener" examples from the docs.

From "Using Closure (verbose)":

https://github.com/yewstack/yew/blob/bfa6c19af971084f9547495388bde9aceeb81aaa/website/docs/concepts/html/events.mdx?plain=1#L387-L390

From "Using gloo (concise)":

https://github.com/yewstack/yew/blob/bfa6c19af971084f9547495388bde9aceeb81aaa/website/docs/concepts/html/events.mdx?plain=1#L454-L457

Both of these also pass a NodeRef into use_effect_with which will only work in certain very simple cases.

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

I'm happy to help resolve this and update the docs, but I'd appreciate some guidance for how you'd like me to word the changes. I'm just hoping to fix this so future people (including my future forgetful self) don't make the same mistakes. This is a subtle footgun that is easy to mess up if you're not very careful.