feat: auto-focus first fields.

This commit is contained in:
elforjani3
2020-12-01 15:14:05 +02:00
parent b5b9764676
commit d299785bfb
8 changed files with 59 additions and 12 deletions

View File

@@ -1,5 +1,6 @@
import {useRef, useEffect} from 'react';
import useAsync from './async';
import useAutofocus from './useAutofocus';
// import use from 'async';
@@ -34,8 +35,7 @@ export function useIsValuePassed(value, compatatorValue) {
return cache.current.indexOf(compatatorValue) !== -1;
}
export default {
export {
useAsync,
useUpdateEffect,
useAutofocus,
}

View File

@@ -0,0 +1,13 @@
import { useRef, useEffect } from 'react';
export default function useAutofocus() {
const ref = useRef();
useEffect(() => {
if (ref.current) {
ref.current.focus();
}
}, [ref]);
return ref;
}