Easy to use utility to detect when user finishes typing, starts typing, or becomes idle!
- 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
DO WHAT EVER YOU WANT! You are free to do what ever you want. enjoy!