Socket
Socket
Sign inDemoInstall

lazy-input

Package Overview
Dependencies
0
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    lazy-input

A lazy React.js input field that only updates when it is told to re-render (fixes issues with Flux backed field data)


Version published
Weekly downloads
16
decreased by-27.27%
Maintainers
1
Install size
21.1 kB
Created
Weekly downloads
 

Readme

Source

lazy-input

npm package Code Climate Test Coverage

A lazy React.js input field that only updates when it is told to re-render (fixes issues with Flux backed field data)

About

Using input elements with Flux can be a pain because actions are asynchronous. Triggering an action in the onChange handler will cause React's default input component to re-render the original value miliseconds before the new value arrives from the store.

LazyInput solves this problem by keeping an internal state for value and only updates that state when given new props, and then only after a lazyLevel has lapsed (default 1s). Otherwise, it works exactly like input. Well, almost. . .

LazyInput expands the type prop slightly to accept textarea in addition to the normal input types. We chose to do it this way because it seemed better than maintaining two packages (LazyInput and LazyTextarea), having lazy-input/input and lazy-input/textarea require statements, or having LazyInput.input and LazyInput.textarea.

var LazyInput = require('lazy-input');
// ...
render: function() {
  return (
    <div>
      // an input element
      <LazyInput type="text" value="some value" onChange={this.onChange} />

      // a test area element
      <LazyInput type="textarea" value="some value" onChange={this.onTextAreaChange} />
    </div>
  );
}

LazyInput can also accept any React Component as the type. For example, if you are using the react-input-placeholder to get placeholder working in older browsers (ex. IE9), then you can pass through the input component directly. There is plenty of rope here to hang yourself though, so be careful.

var Input= PlaceholderShim.input;
// ...
<LazyInput type={Input} value="some value" onChange={this.onChange} />

Installing

Installing via npmjs

npm install --save lazy-input

Using

LazyInput = require('lazy-input');
// ...
<LazyInput type="text" value={this.state.myFluxValue} onChange={this.onChange} />

Examples

git clone https://github.com/HurricaneJames/lazy-input.git
cd lazy-input
npm install
npm run examples
open localhost:8090

Changelog

v2.0 - Updated to support React 15.x, added examples

  • v2.0.0 in theory there is no reason this should not work with React 0.13+, just like before, the only thing that changed was the tests and the addition of examples.

v1.1 - LazyInput types can now include any React Component class. Thanks go to Riku Rouvila.

  • v1.1.1 - fixed bug where html5 descriptive input types crashed (ex. type="tel"). Thanks go to Eric Fennell for reporting the bug.

Keywords

FAQs

Last updated on 30 Apr 2016

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc