![](/img/trans.png)
[英]Component not changing after state change (componentDidMount fetch) - React
[英]Changing/Processing data after async fetch in componentDidMount
我正在尝试在componentDidMount函数中获取数据后更改数据。
假设我要抓取一个对象:
{
text: "hello world"
}
但是我想加''!'' 在componentDidMount中获取此字符串之后。 我的问题是,我应该在哪里编辑获取的数据? 当我尝试在componentDidMount中进行编辑时,总是收到错误消息,提示我无法编辑“未定义”。
提前致谢。
更具体一点,如果还显示提取功能和修改功能,效果会更好。 但是,我可以猜到类似的东西:
componentDidMount() {
fetch(reqObj)
.then(json => {
const modifyJson = JSON.stringify(json) + '!'
this.setState({text: modifyJson})
})
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.