Implement a function useFocus() that allows focusing on an HTML element programmatically.
The function should:
ref property to attach to an element.focus() method that focuses the attached element when called.focus() on an unmounted element does not throw an error.Examples
const { ref, focus } = useFocus(); const input = document.createElement('input'); ref.current = input; focus(); console.log(document.activeElement === input); // true
JavaScript Function
No test results yet
Click "Run" to execute tests