0.0.3 • Published 6 years ago

watch-props v0.0.3

Weekly downloads
2
License
ISC
Repository
-
Last release
6 years ago

watch-props

A higher-order component that adds watch props features to the react component

Install

npm i --save watch-props

Usage

import React from 'react'
import watchProps from 'watch-props'

@watchProps
class App extends React.Component{
  watch={
     id: function(newValue, oldValue){
        console.log(newValue, oldValue) //print "100, 1"
     }
  }
}

class Home extends React.Component{
  state = {
    id: 1
  }
  
  componentDidMount(){
     setTimeout(()=>{
        this.setState({
           id: 100
        })
     },1000)
  }

   render(){
     return <App id={this.state.id} />
   }
}