Correct way to handle `NodeRef` reassignments?
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 32.8k
- Forks
- 1.5k
- Avg merge
- 5h 34m
- Merged PRs (30d)
- 2
Description
Question
I'm using refs to register event listeners for non-Yew-supported event types. Following the node_refs example, it makes sense to use the rendered method to do setup on first render. But what happens when the value of the ref changes? E.g. if the Node being refd is rendered conditionally? In React, this is where I would reach for a "callback ref" passed a class method or a function with a bound this. Maybe the Yew analog would be a Callback to dispatch a message upon ref assignment?
What I've tried
I can store the result of ref.get() in the component struct and do an equality check in rendered, but this strikes me as roundabout and not incredibly ergonomic. It's possible that not many people have (or have expressed) this use case, and thus it's not even on yew's radar. That's perfectly alright. I'm just wondering if there's already a "blessed" strategy for this that I'm simply overlooking.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the node_refs example and the component's rendered lifecycle, both referenced in the issue. Determine how NodeRef behaves when its target is conditionally reassigned and whether an existing callback or message pattern covers that case. Done means documenting the supported strategy or clearly scoping the API change required.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- frontend, web-dev
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100