父组件里引用子组件
<NotifyInfo
notifyData={this.state.notifyData}
infoData={this.state.infoData}
/>
子组件写法
import React, { Component } from 'react'
export default class NotifyInfo extends Component {
constructor(props) {
super(props)
this.state = {//创建变量并初始化
seeData: [],
allData: [],
}
}
//使用箭头函数可绑定this指向,就可以不用bind
clearSeeData = () => {
this.setState({
allData: this.props.notifyData,
seeData: this.props.notifyData,
})
}
//使用父组件传过来的值 this.props.notifyData
//使用组件本身的值 this.state.data
//render外面声明表达式
//render里面使用表达式
render() {
return (//jsx表达式能直接使用
{this.state.allData.length > 0 ? (
<Button block onClick={this.addMore}>
{this.state.addTxt}
</Button>
) : null}
)}
}