在更新组件之前进行 React 渲染

React renders before updating component

我希望我的 React 组件在呈现之前更新状态。现在我有一组问题是从 API 中得到的。因此,根据 url,问题会发生变化。当我离开组件并返回(使用新状态)时,它首先显示旧状态一两秒钟,然后再显示新状态。

您应该使用 componentWillUnmount 生命周期方法来清理您的状态数据

https://reactjs.org/docs/react-component.html#componentwillunmount