/element-focus

React hook for check focus state of elements

Primary LanguageJavaScriptMIT LicenseMIT

@rehooks/element-focus

React hook for check focus state of elements

Note: This is using the new React Hooks API Proposal which is subject to change until React 16.7 final.

You'll need to install react, react-dom, etc at ^16.7.0-alpha.0

Install

yarn add @rehooks/element-focus

Usage

import useInputValue from '@rehooks/input-value';
import useElementFocus from '@rehooks/element-focus';

function MyComponent() {
  const { isFocused, bind } = useElementFocus();
  // bind = { onFocus: [function], onBlur: [function] }
  return (
    <div>
      <input {...bind} />
      <div>This input is {isFocused ? "focused" : "not focused"}</div>
    </div>
  );
}