This package has been deprecated

Author message:

Please use @snappmarket/hooks instead

@snappmarket/use-focus

0.2.5 • Public • Published

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;
};

Package Sidebar

Install

npm i @snappmarket/use-focus

Weekly Downloads

0

Version

0.2.5

License

MIT

Unpacked Size

6.37 kB

Total Files

7

Last publish

Collaborators

  • jrjs
  • mahsamesbah
  • milad.kiani
  • mostafa_rastegar
  • rezaerami