【发布时间】:2018-03-29 13:27:58
【问题描述】:
反应组件:
class Info extends Component {
constructor() {
this.state = {
editAccount: false
}
this.changeTrue = this.changeTrue.bind(this);
this.changeFalse = this.changeFalse.bind(this);
}
changeTrue() {
this.setState({ediAccount: true}
}
changeFalse() {
this.setState({ediAccount: false}
}
render() {
const specific_style = this.state.editAccount ? { background: 'red'} : { background : 'yellow' }
return (
<div>
<TextField
id='first_name'
inputStyle={ specific_style}
value={this.state.first_name}
/>
<button onClick={this.changeTrue}>Click True</button>
<button onClick={this.changeFalse}>Click False</button>
</div>
)
}
}
让这个组件和 editAccount 改变状态不会重新渲染应用样式更改?不重新渲染 TextField 吗?有人知道为什么吗?
【问题讨论】:
-
editAccount来自哪里?red和yellow应该是字符串。你忘了用/>关闭你的TextField组件。请更正这些问题。 -
您的代码中缺少许多部分。你能发布完整的代码吗?
-
再次发表评论,因为不确定是代码中的错字还是此处:
this.setState({ediAccount: true}
标签: reactjs material-ui