0.1.5 • Published 5 years ago

react-change-detector v0.1.5

Weekly downloads
3
License
ISC
Repository
github
Last release
5 years ago

React Change Detector

This package enable you to use change detector in you react form or app only on the states you provide to it.

Installation

npm i react-change-detector --save

How To Use

To use this you need to import ChangeDetector component in you app like this

import React, { Component, createRef } from 'react';
... some code
import { ChangeDetector } from 'react-change-detector';
... some code
class App extends Component {
    state = {
        test1: '1',
        test2: [2]
        test3: {a : 1},
        // you can name whatever you want
        detector: null
    }
    
    setDetector(detector) {
        this.setState({detector: detector})
    }

    // for getting accesst its functions
    changeDetector = createRef()

    onClick = () => {
        if (this.state.detector.isChangeDetected()) {
            // code if change is detected
        }
    }

    render() {
        <ChangeDetector ref={this.changeDetector}
            test1={this.state.test1}
            test2={this.state.test2}
            test3={this.state.test3}
            changeDetector={this.setDetector.bind(this)}
        >
        .. your form code or child components
        </ChangeDetector>
    }
}
0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago