react-use-variable
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

react-use-variable custom hook

React hook to update variable refs automatically

Install

npm install react-use-variable

Usage

export const Component: FunctionComponent<Props> = ({ something }) => {
  const ref = useVariable(something);

  // is the same as:

  const ref = useRef(something);
  ref.current = something;

  const [state, ref, setState] = useStateVariable(something);

  // is the same as:

  const [state, setState] = useState(something);
  const ref = useRef(state);
  ref.current = something;
};

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i react-use-variable

Weekly Downloads

35

Version

1.2.0

License

MIT

Unpacked Size

3.76 kB

Total Files

14

Last publish

Collaborators

  • nils.drechsel