Easy to use utility to detect when user finishes typing, starts typing, or becomes idle!
from version 1.2.0
the hook was renamed for better naming to useOnType
- React hook or component base
- Allows to customize the detection delay
- Allows to wrap your onChange
- High performance, 0 re-renders by default
- written in Holy typescript
npm install use-ontype
// the hook
import { useOnType } from "use-ontype";
// for components
import { createOnTypeHandler } from "use-ontype";
import { useOnType } from "use-ontype";
function Example() {
const onType = useOnType(
{
onTypeStart: (val) => console.log("started", val),
onTypeFinish: (val) => console.log("finished", val),
onChange: (event) => console.log("event", event),
},
800,
);
return (
<div>
<TextField
fullWidth
label="find user by email"
{...onType}
variant="outlined"
/>
</div>
);
}
The hook takes two arguments callbacks
and delay
Called when user starts typing
Called when user finishes typing
use-ontype
uses onChange and you can add your custom onChange here while keeping the event tracking
Delay is the interval which we check if user is still typing or not. default: 1000ms
- need to clean the example file, its quite messy
DO WHAT EVER YOU WANT! You are free to do what ever you want. enjoy!