useRef
Bind and get DOM elements
Examples
Basic Usage
bind DOM element:DIV
DOM Element
Basic usage
Bind and get DOM element
Advanced Usage
bind DOM element content: [list-1, list-2, list-3 ]
list-1
list-2
list-3
Basic usage
Bind and get DOM element list
API
const [ref, setRef] = useRef(initialValue?: Element | Element[] | null);
const [ref, setRef] = useRef(initialValue?: Element | Element[] | null);
Params
Property | Description | Type | Default |
---|---|---|---|
initialValue | Optional, if it is a DOM array, pass in an empty array as the default value | Element | Element[] | - |
Result
Property | Description | Type |
---|---|---|
ref | DOM element | Accessor<Element> |
setRef | bind DOM element | (el: Element, index?: number) => void |