Search code examples
sqlitereact-nativeasyncstorage

react-native array.map with asyncstorage.getItem


I've been trying to retrive data from asyncstorage using react native.

Here is what i've done so far:

import React, { Component } from 'react';

import {
  Text,
} from 'react-native';

class GetData extends Component {
  constructor() {
    super()
    this.state = {
      dataLocalIds: [
        "data1Data",
        "data2Data",
        "data3Data",
        "data4Data",
        "data5Data",
        "data6Data"
      ],
    }

    this.state.dataLocalIds.map((value, index) => {
      this.data = this.getDatas(value, index);
    })
  }

  async getDatas(value, index) {
    try {
      const value = await AsyncStorage.getItem(value).then(val => {
        return JSON.parse(val)
      });
      return value
    } catch (err) {
      throw err
    }
  }

  renderScreen = () => {
      return (
        <Text> Hello World </Text>
      );
  }

  render() {
    return (
      this.renderScreen()
    );
  }
}

export default GetData;

Problem is: Apps crash with error, " the bind value at index 1 is null ".

Stacktrace does not point to lines inside my code. Instead, it points to sqlite and asyncstorage.

I really have no idea how to solve this issue. Help Would be appreciated.


Solution

  • Hi MacFlyer have you tried using multiget (https://facebook.github.io/react-native/docs/asyncstorage.html#multiget)?