【发布时间】:2020-03-03 12:32:56
【问题描述】:
下面是我的代码。我正在使用 API 并在当前页面上获取一些数据。现在我想在重新加载页面或返回或再次前进时保存此页面的状态。
在这里,我从上一页 api 获取 featureGroupID 并将此处存储在全局变量 customerID 中。
我知道它是使用本地存储完成的,但由于我对 Reactjs 非常陌生,我不知道如何保存状态。有人可以帮忙吗?
class CustomerList extends Component {
state = {
isLoading: true,
users: [],
error: null,
customerID: null
};
componentDidMount() {
fetch('http://localhost:8080/entity/getEntityByFeatureGroup/'+this.customerID)
.then(response => response.json())
.then(data =>
this.setState({
users: data,
isLoading: false,
})
).catch(error => this.setState({ error, isLoading: false }));
}
render() {
var logTable = this.props;
console.log(logTable);
var customerColumnList = this.props;
this.customerID = customerColumnList.location.aboutProps.id.featureGroupID;
var headerName = customerColumnList.location.aboutProps.name.logTable.headerName;
const { isLoading, users, error } = this.state;
return (....
【问题讨论】:
标签: reactjs local-storage react-navigation react-props