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

Correct way to handle NodeRef reassignments? #1439

Open
EndilWayfare opened this issue Jul 22, 2020 · 1 comment
Open

Correct way to handle NodeRef reassignments? #1439

EndilWayfare opened this issue Jul 22, 2020 · 1 comment
Labels
A-yew Area: The main yew crate question

Comments

@EndilWayfare
Copy link
Contributor

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.

@WorldSEnder
Copy link
Member

I can see callback refs slowly appearing on the horizon, specifically with #2551 and #2567

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-yew Area: The main yew crate question
Projects
None yet
Development

No branches or pull requests

3 participants