Reactjs 如何使用ReactXP存储api?
我是Reactjs 如何使用ReactXP存储api?,reactjs,react-native,reactxp,Reactjs,React Native,Reactxp,我是ReactXP新手,我正在尝试使用MicrosoftReactXP框架创建一个小应用程序。我想在本地存储器中保存键值对。微软提供了一个叫做存储的api 我正试着把它当作 onLoginPressed(){ const user = new User(this.state.userEmail, this.state.password); RestClient.login(user).then(success => { alert(
ReactXP
新手,我正在尝试使用MicrosoftReactXP
框架创建一个小应用程序。我想在本地存储器中保存键值对。微软提供了一个叫做存储的api
我正试着把它当作
onLoginPressed(){
const user = new User(this.state.userEmail, this.state.password);
RestClient.login(user).then(success => {
alert(success.message);
Storage.setItem('userEmail', success.userInfo.userEmail);
}).catch(error => {
alert('Error in login');
});
}
但它显示了一个错误
ERROR in [at-loader] ./src/Login.tsx:102:21
TS2339: Property 'setItem' does not exist on type '{ new (): Storage; prototype: Storage; }'.
由于文档不好,我无法使用它。有人能帮我吗?我找到了如下解决方案
onLoginPressed(){
const user = new User(this.state.userEmail, this.state.password);
RestClient.login(user).then(success => {
alert(success.message);
RX.Storage.setItem('userEmail', success.userInfo.userEmail);
}).catch(error => {
alert('Error in login');
});
}
你可以得到如下结果:
RX.Storage.getItem('userEmail').then(success => {
this.setState({
userEmail: success
});
});