[英]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.