0.1.1 • Published 1 year ago

react-next-tick v0.1.1

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

React nextTick

Downloads Vulnerabilities Dependencies Coverage Stars

Table of contents

Overview

A React equivalent of Vue's nextTick() function.

Installation

npm install react-next-tick

ESLint configuration

module.exports = {
  rules: {
    ...
   "react-hooks/exhaustive-deps": [
      "warn",
      { additionalHooks: "^useNextTick$" }
    ],
    ...
  }
}

Usage

import * as React from "react";
import { useNextTick } from "react-next-tick";

function Component(): React.JSX.Element {
  const [value, setValue] = React.useState(0);

  const deferred = useNextTick(() => {
    console.log(value);
  }, [value]);

  return (
    <button onClick={clickHandler} type="button">
      Sample button
    </button>
  );

  function clickHandler(): void {
    setValue(1);
    deferred.immediate(); // Output: 0
    deferred(); // Output: 1
  }
}

Related packages

0.1.1

1 year ago

0.1.0

1 year ago