react-conditionally-update

0.1.0 • Public • Published

react-conditionally-update

A high order function to decorate a react component to conditionally update the rendered component based on the rendered result.

Demo

npm i && npm start

Example:

 
import React, { Component } from 'react';
import conditionallyUpdate from 'react-conditionally-update';
 
class DemoComponent extends Component {
    constructor(props) {
        super(props);
 
        this.state = {
            width: 200,
            height: 100,
            backgroundColor: 'red'
        };
    }
    
    // method required to check the condition and update the component with setState
    conditionallyUpdateCallback() {
        if (this.state.height === 100) {
            this.setState({
                height: 200
            });
        }
    }
 
    render() {
        return (
            <div style={this.state}></div>
        );
    }
}
 
export default conditionallyUpdate(DemoComponent);
 

Readme

Keywords

none

Package Sidebar

Install

npm i react-conditionally-update

Weekly Downloads

0

Version

0.1.0

License

MIT

Last publish

Collaborators

  • ralphwen