Socket
Book a DemoInstallSign in
Socket

react-deferred-input

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-deferred-input

React input component that defers onChange handler until input is blurred

latest
Source
npmnpm
Version
0.3.8
Version published
Maintainers
1
Created
Source

React Deferred Input

npm install react-deferred-input

See demo HERE.

What is the purpose of this component?

Form inputs in React can either be controller or uncontrolled (see here). Controlled components always display the value prop they are passed and need to trigger the onChange handler every time a character is added or removed so that they can be updated. Uncontrolled components render the initial defaultValue prop they get passed and after that they render what the user types into them.

This component gives you the functionality of a controlled component that always displays the value prop that it is given EXCEPT when a user is focused on the input then it waits till the user blurs and then only triggers the onChange (and onBlur) handlers if the value has change.

This can dramatically reduce the number of network requests that get sent.

Example Usage

import React, { Component } from 'react';
import DeferredInput from 'react-deferred-input';

class MyComponent extends Component {
  render() {
    return (
      <DeferredInput value='initial value' onChange={this.handleChange} />
    );
  }

  handleChange(value) {
    console.log("this is only called when the input is blurred with the value: ", value);
  }
}

Options/Available props

Prop NameDescriptionDefault Value
valueinput valueString: ''
onChangehandler called with one argument (input value) on blur (required)Function: undefined
onBlurhandler called with one argument (input value) on blurFunction: undefined
blurOnEntershould input blur when press ENTER keyBoolean: false
focusOnMountshould input be focused when initially mountedBoolean: false
clearOnChangeshould input value be cleared on blurBoolean: false
inputComponentcomponent to be used for actual input'input'

Any other custom props will be passed on to input component.

License

MIT

Keywords

react-component

FAQs

Package last updated on 18 Apr 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts