![](/img/trans.png)
[英]updating react component state using this.setState isn't re-rendering the component
[英]React Stateful Class Component: using “this.setState” to update properties of the state, not working. No error. State doesn't change
我知道有几个问题可以解决这个问题,但它们对我没有帮助。 我基本上有这个:
state: {
location: 'Tahiti',
price: ['2000'],
day: {August}
}
componentDidMount() {
const updatedprice = '1800'
this.setState({price: updatedprice})
}
除了价格我尝试将 object 设置为新的 state 之外,我对其他属性所做的或多或少相同。 这一直对我有用,并且正在其他地方工作。 出了什么问题? 任何指针?
所有的组件基本上都是这样的。 我只是想修改 state。
PS我在设置state时做了一个console.log on:this.setState({price: updatedprice}),它给出了未定义的,这也发生在其他属性上。 虽然,我没有错误,只是当我控制台记录 state 时,它显示零差异。
你只是语法错误。
this.setState({price: updatedprice});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.