0

I am new in ReactXP and I am trying to create a small app using Microsoft ReactXP framework. I want to save key value pair in my local storage. Microsoft provided an api called Storage https://microsoft.github.io/reactxp/docs/apis/storage.html https://github.com/Microsoft/reactxp/blob/master/src/web/Storage.ts

And I am trying to use it as

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');
        });
    }

but it showing an error

ERROR in [at-loader] ./src/Login.tsx:102:21
    TS2339: Property 'setItem' does not exist on type '{ new (): Storage; prototype: Storage; }'.

because of poor documentation I am not able to use it. Can anybody help me?

Rohit Luthra
  • 1,256
  • 17
  • 27

1 Answers1

1

I found the solution as follows

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');
        });
    }

and you can get it as follows :

RX.Storage.getItem('userEmail').then(success => {
     this.setState({
          userEmail: success
     });
});
Rohit Luthra
  • 1,256
  • 17
  • 27