export default class PageView extends Component {
state = {
contents: [],
contentsLen: 0
}
add = () => {
this.setState(prev => {
const cot = prev.contents.slice()
cot.push({ text: 'hello world' })
return {
contents: cot,
contentsLen: cot.length
}
})
}
remove = () => {
this.setState(prev => {
const cot = prev.contents.slice()
cot.pop()
return {
contents: cot,
contentsLen: cot.length
}
})
}
render () {
return (
<View className='container'>
{this.state.contents.map((item, index) => (
<Text key={index}>{item.text}</Text>
))}
<Button className='btn-max-w button_style' plain type='default' onClick={this.add}>add line</Button>
<Button className='btn-max-w button_style' plain type='default' disabled={this.state.contentsLen ? false : true} onClick={this.remove}>remove line</Button>
</View>
)
}
}