CR97
CR97

Reputation: 85

React-Native-AsyncStorage save integer item

I am try to save integer variable to the AsyncStorage, however it return me the error

the bind value at index 1 is null

SET Item

This is the code that i save item

AsyncStorage.setItem(
      Common.CURRENT_CHILD,
      this.state.child.toString(), //14
      () => {
        NavigationService.navigate('Home', {
          childName: this.state.childName
        });
      }
    );

GET Item

This is the code that i retrieve item

    AsyncStorage.getItem(Common.CURRENT_CHILD, (err, result) => {
      if (result === null) {
       console.log(err);
     } else {
      this.setState(
     {
        child: result
     },
      () => {
        console.log('Result -', result);
      }
    );
  }
})

Upvotes: 0

Views: 1667

Answers (1)

Saloni Parikh
Saloni Parikh

Reputation: 154

AsyncStorage.setItem(
  Common.CURRENT_CHILD,
 ""+ this.state.child.toString(), //14
  () => {
    NavigationService.navigate('Home', {
      childName: this.state.childName
    });
  }
);

you can write "" while set item to Asyncstorage and try to use console.log while getting Item before if statement or

write

  AsyncStorage.setItem(
      Common.CURRENT_CHILD,
     ""+ this.state.child, //14
      () => {
        NavigationService.navigate('Home', {
          childName: this.state.childName
        });
      }
    );

Upvotes: 1

Related Questions