@marinoandrea/react-debounced-input
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

react-debounced-input

ci codecov npm GitHub

Simple React input component that debounces calls to onChange. It behaves like a <input> everywhere else.

Install

With npm:

npm i --save @marinoandrea/react-debounced-input

With Yarn:

yarn add @marinoandrea/react-debounced-input

Usage

Search bar using @tanstack/react-query:

import { DebouncedInput } from "@marinoandrea/react-debounced-input";
import { useState } from "react";
import { useQuery } from '@tanstack/react-query'


export default function App() {
  const [query, setQuery] = useState("");

  const query = useQuery({
    queryKey: ["search", query],
    queryFn: async () => {
        // perform some network request using the query
    }
  });

  return (
    <div>
      <DebouncedInput
        debounceMs={300}
        onChange={(e) => setQuery(e.currentTarget.value)}
       />
    </div>
  );
}

Note: The call to setQuery is gonna be debounced by 300 milliseconds but the input value is still gonna change immediately as it's not controlled here.

Authors

See also the list of contributors who participated in this project.

Dependencies (0)

    Dev Dependencies (26)

    Package Sidebar

    Install

    npm i @marinoandrea/react-debounced-input

    Weekly Downloads

    1

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    8.31 kB

    Total Files

    12

    Last publish

    Collaborators

    • marinoandrea