title: How to store one record into an existing array with AsyncStorage React Native
body: <p>I have an existing array myItems and the list of items, fetched from API (array itemsFromApi) and rendered as a Flatlist. <strong>I want to store each item (not an array of items) into an existing array and save it local.</strong></p>
  
  <p>What i tried to do:</p>
  
  <ol>
  <li>Fetch array of items from api and render it as an Flatlist.</li>
  <li>Save each item to an existing array myItems (using useState)</li>
  <li>Use JSON.stringify and JSON.parse to store an array myItems as a value via AsyncStorage</li>
  </ol>
  
  <p>What i have: </p>
  
  <ol>
  <li>Fetch items and storing it into array myItems works good. </li>
  <li>In AsyncStorage is stored only one item, although i store an array
  using AsyncStorage.</li>
  <li>After re-render an array myItems is empty, AsyncStorage has only one item.</li>
  </ol>
  
  <p>Here is peace of code:</p>
  
  <pre><code>// Array myItems, where i'd like to store the data
  const [myItems, setMyItems] = useState([]); 
  
  // Array of data from api
  const [itemsFromApi, setItemsFromApi] = useState([]); 
  
  // Fetch items from API and render it as a Flatlist, works good
  const getItems = async () =&gt; {
     const response = await api.get('/...');
     setItemsFromApi(response.data)
  };
  
  &lt;FlatList 
      data={itemsFromApi}
      keyExtractor = { (item, index) =&gt; index.toString() }
      renderItem={({ item })=&gt;{
             return (
               &lt;TouchableOpacity&gt;
                   &lt;Text&gt;{item.id}&lt;/Text&gt;
                   &lt;Text&gt;{item.title}&lt;/Text&gt;
                   &lt;Button title="Add" onPress={()=&gt;{addItem(item))} /&gt;
              &lt;/TouchableOpacity&gt;
         )
     }}
   /&gt;
  
  // Save fetched items to array myItems
  const addItem = (item) =&gt; {
     setMyItems([...myItems, item]);
     storeData();
  };
  
  
  // trying to store array myItems using AsyncStorage
   const storeData = async (myItems) =&gt; {
          try {
            await AsyncStorage.setItem('STORAGE_KEY', JSON.stringify(myItems));
            Alert.alert('Saved', 'Successful');
          } catch (error) {
              Alert.alert('Error', 'There was an error.')
          }
        };
  
  // trying to retrieve data 
  const retrieveData = async () =&gt; {
    try {
      const value = await AsyncStorage.getItem('STORAGE_KEY');
        if (value !== null) {
              console.log(JSON.parse(value))
          }
        } catch (error) {
              console.log(error)
        }
          return null;
    };
  
  </code></pre>
  
  <p>I'm definitely doing something wrong, but I don’t understand what.
  Thanks in advance!</p>