npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-input-with-debouncing

v1.1.0

Published

A small lightweight React input component with debouncing that can be used in place of normal <input /> or <textare />. The component renders input with debouncing onChange event.

Downloads

2

Readme

react-input-with-debouncing

A small lightweight React input component with debouncing that can be used in place of normal <input /> or <textarea /> fields.The component renders input with debouncing onChange event.

NPM JavaScript Style Guide node-current npm peer dependency version

Installation

NPM

npm install --save react-input-with-debouncing

Usage

import React, { Component } from 'react'

import InputWithDebouncing from 'react-input-with-debouncing'
import 'react-input-with-debouncing/dist/index.css' //import of index.css is totally optional.

class ExampleInputWithDebouncing extends Component {
  constructor(props) {
    super(props);
    this.state = {
      value: '';
    }
  }

  render() {
    return (
      <InputWithDebouncing
        type="text"
        placeholder='Search'
        className='input-search'
        minLength={1}
        debounceTimeout={1000}
        onChange={(e) => this.setState({ value: e.target.value })}
        value={this.state.value}
      />
    )
  }
}

Options

Default prop values

<InputWithDebouncing
  element= 'input',
  type= 'text',
  onKeyDown= {undefined},
  onBlur= {undefined},
  value= {undefined},
  minLength= {0},
  debounceTimeout= {500},
  notifyOnEnter= {true},
  notifyOnBlur= {true},
  inputRef= {undefined}
 />

Usage explanation

Note: This package is primarily built and tested on <input /> and <textarea /> keeping use cases in mind. But you can explore.

element : PropTypes.oneOfType([PropTypes.string, PropTypes.func]) (default: 'input')

element prop can take either one of the value from input or textarea.

type : PropTypes.string (default: 'text')

Default value of type prop is text but you can specify other options like number.

onChange: PropTypes.func.isRequired (Mandatory Props)

onChange function is called with event passed through it on input change with debounced timeout.

value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]) (default: undefined)

Default value of input is undefined. If not specified, then input works as non-controlled input.

minLength: PropTypes.number (default: 0)

minLength prop specifies minimal length of text to start notify, if value becomes lesser then minLength (after removing some characters), there will be a notification with empty value ''.

debounceTimeout: PropTypes.number (default: 500)

debounceTimeout specifies the debouncing time in ms. If you specify debounceTimeout = -1, then it disable automatic notifications completely. On pressing of Enter, notification will be triggered only in this case.

notifyOnEnter: PropTypes.bool (default: true)

On pressing Enter, notification of current value will be triggered immediately. Notification value follows the same rule as with debounced notification, so if length is less, then minLength - empty value '' will be sent back.

notifyOnBlur: PropTypes.bool (default: true)

In this case, notification will be sent only when focus leaves the input field.

inputRef: PropTypes.func (default: undefined)

Pass ref={inputRef} to generated input element. ref is a special prop in React, and hence renamed ref to inputRef.

className : className props will be applied directly on generated input.

This is an arbitrary prop which is directly applied to input field.

placeholder : placeholder props will be applied directly on generated input.

This is an arbitrary prop which is directly applied to input field.

Test

Unit testing with lint testing

npm run test

Unit testing

npm run test:unit

Lint testing

npm run test:lint

Testing during development

npm run test:watch

License

MIT © Satyendra Pandit