Skip to content
This repository was archived by the owner on Jul 19, 2020. It is now read-only.

Latest commit

 

History

History
27 lines (18 loc) · 596 Bytes

refs.md

File metadata and controls

27 lines (18 loc) · 596 Bytes
description
Out-of-band DOM access

Refs

Refs

The ref keyword can be used inside of any HTML element or component to get the DOM Element that the item is attached to. This can be used to make changes to the DOM outside of the view lifecycle method.

This is useful for getting ahold of canvas elements, or scrolling to different sections of a page.

The syntax is:

// In create
self.node_ref = NodeRef::default();

// In view
html! {
    <div ref=&self.node_ref></div>
}

// In update
let has_attributes = self.node_ref.try_into::<Element>().has_attributes();