Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/433.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 无状态组件每次呈现父级时比较参数_Javascript_Reactjs - Fatal编程技术网

Javascript 无状态组件每次呈现父级时比较参数

Javascript 无状态组件每次呈现父级时比较参数,javascript,reactjs,Javascript,Reactjs,我有一个这样编写的无状态组件 //stateless component const ComponentOne = ({ month }) => { console.log(month); // print incremental of 1 when I render parent component } 月份从其父级传递 render(){ return( <ComponentOne month={ month }/> ) } re

我有一个这样编写的无状态组件

//stateless component
const ComponentOne = ({ month }) => {
    console.log(month); // print incremental of 1 when I render parent component
}
月份从其父级传递

render(){
    return(
        <ComponentOne month={ month }/>
    )
}
render(){
返回(
)
}

我可以改变月份并把它传下去。如何检查每次父级渲染后的月份是否不同?使用组件将接收道具?但该组件一直是无状态组件。

哑组件必须仅用于呈现,并且您应该处理主组件中的所有逻辑

您可以在父组件的函数中验证月份,也可以将另一个道具传递给哑组件,该道具将是月份道具的上一个值,然后进行类似的比较

const ComponentOne = ({ month, prevMonth }) => {

    if(month != prevMonth) {
          //do what you want here
    }
    console.log(month); // print incremental of 1 when I render parent component
}

render(){
    return(
        <ComponentOne month={ month } prevMonth={this.state.prevMonth}/>
    )
}
const ComponentOne=({month,prevMonth})=>{
如果(月!=上个月){
//你想在这里干什么就干什么
}
console.log(month);//在呈现父组件时打印增量1
}
render(){
返回(
)
}