useRefInit<T> function
Returns a mutable Ref object with Ref.current property initialized to initialValue
.
Changes to the Ref.current property do not cause the containing DartFunctionComponent to re-render.
The returned Ref object will persist for the full lifetime of the DartFunctionComponent. 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 DartFunctionComponent.
Example:
UseRefTestComponent(Map props) {
final countRef = useRefInit(1);
handleClick([_]) {
ref.current = ref.current + 1;
window.alert('You clicked ${ref.current} times!');
}
return react.Fragment({}, [
react.button({'onClick': handleClick}, ['Click me!']),
]);
}
Learn more: reactjs.org/docs/hooks-reference.html#useref.
Implementation
Ref<T> useRefInit<T>(T initialValue) => Ref.fromJs(React.useRef(initialValue));