0.2.5 • Published 4 years ago

@snappmarket/use-focus v0.2.5

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

useFocus

😵 focus on every thing you want

version downloads PRs Welcome MIT License

Watch on GitHub Star on GitHub

get started

We provide two way of using this package single or multi :

npm i @snappmarket/use-focus
OR
npm i @snappmarket/hooks

usage

import useFocus from '@snappmarket/use-focus';
// or 
// import { useFocus } from '@snappmarket/hooks';


const MyComponenet = props => {
  const focusRef = useFocus(null);

  return (<input type="text" ref={focusRef}/>)
};

source code

import { useEffect, useRef } from 'react';

/**
 * Focus on a ref after render
 * @param initialRef
 * @returns {React.MutableRefObject<*>}
 */
export default initialRef => {
  const ref = useRef(initialRef);
  useEffect(() => {
    setTimeout(() => {
      ref.current.focus();
    }, 100);
  }, []);

  return ref;
};
0.2.5

4 years ago

0.2.3

4 years ago

0.2.1-alpha.0

4 years ago

0.1.24

4 years ago

0.1.22

4 years ago

0.1.21

4 years ago

0.1.20

4 years ago

0.1.10

4 years ago

0.1.11

4 years ago

0.1.13

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago