[英]React state not rendering
All I'm trying to do is render the state 'draft' onto a H1 tag and it simply won't do it! 我要做的就是将状态“草稿”渲染到H1标签上,而它根本不会这样做! It's driving me nuts. 它让我发疯。 What am I doing wrong? 我究竟做错了什么?
The initial H1 tags of 'I can see this' are visible however the 2nd pair don't show up at all.. 最初的H1标签“我可以看到”可以看到,但是第二对根本没有出现。
import React, { Component } from 'react';
import Header from '../components/Header'
import NewTodo from '../components/NewTodo'
import List from '../components/List'
class TodoContainer extends Component{
constructor(){
super()
this.state = {
todos: ['bathroom', 'kitchen', 'loungeroom'],
draft: 'READ ME!'
}
}
render(){
return (
<div>
<h1>I can see this</h1>
<h1>{() => this.state.draft}</h1>
</div>
)
}
}
export default TodoContainer
You need to write this line: 您需要编写以下行:
<h1>{this.state.draft}</h1>
Rather than this line: 而不是这一行:
<h1>{() => this.state.draft}</h1>
Example code: http://jsfiddle.net/w66zxefv/1/ 示例代码: http : //jsfiddle.net/w66zxefv/1/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.