GithubHelp home page GithubHelp logo

andrewraycode / lazy-input Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hurricanejames/lazy-input

0.0 3.0 0.0 18 KB

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

License: MIT License

JavaScript 97.07% Shell 2.93%

lazy-input's Introduction

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} />

Changelog

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.

lazy-input's People

Contributors

hurricanejames avatar rikukissa avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.