Skip to content

Pattern for JS components which need a DOM object #561

Answered by lukechu10
stopbystudent asked this question in Q&A
Discussion options

You must be logged in to vote

The best solution, which also happens to be the simplest and most idiomatic is just to create a new component whose job is just to bind to the JS library and nothing else. For example, you could create a FullCalenderWidget component that creates a div and calls the JS code.

You can then just use this component inside your if/else instead of putting the div there.

Also I'm not sure if you're aware but you can use NodeRef with .get_web_sys() to get a raw handle to a web_sys::Node which you should be able to pass directly to your JS library. This is nicer to use and less error-prone than using HTML ids.

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@stopbystudent
Comment options

@lukechu10
Comment options

@stopbystudent
Comment options

Answer selected by stopbystudent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants