useRef
External Documentation
Ref<
Returns an empty mutable Ref object.
To initialize a ref with a value, use useRefInit instead.
Changes to the Ref.current property do not cause the containing function component to re-render.
The returned Ref object will persist for the full lifetime of the function component. Compare to createRef which returns a new Ref object on each render.
Note: there are two rules for using Hooks:
- Only call Hooks at the top level.
- Only call Hooks from inside a function component.
Example:
final MyComponent = registerFunctionComponent((props) {
final inputRef = useRef<InputElement>(null);
return div(children: [
input({'ref': inputRef.jsRef}),
button(text: 'Focus', onClick: () => inputRef.current?.focus()),
]);
});
Implementation
Ref<T?> useRef<T>([T? initialValue]) => useRefInit<T?>(initialValue);