title: Porblem with passing data between screen (Too many re-renders)
body: <p>I've got a problem with passing data between screens. Here is the screen where I'm taking input:</p>
  <pre><code>import React, {useState} from 'react'
  import {View, TextInput, Button, StyleSheet, TouchableWithoutFeedback, Keyboard} from 'react-native'
  import { useGlobal } from 'reactn';
  import Card from '../components/Card'
  import colors from '../constants/colors';
  
  
  
  
  type Props={
  
  navigation:any
  }
  
  const AddingScreen = (props:Props) =&gt;{
      
      let annmountAndProductToSend:any;
      
      const [enteredProduct, setEnteredProduct] = useState&lt;string&gt;('');
      const [amount, setAmount] = useState&lt;any&gt;('');
     
      
      function enteredProductHandler(enteredText:string):void
      {
          
          setEnteredProduct(enteredText);
      }
  
      function amountHandler(enteredText:any):void
      {
          let amountAndProduct;
          const amm = parseInt(enteredText);
  
          if(isNaN(enteredText) || enteredText &gt; 1)
          {
              setAmount(enteredText);
              amountAndProduct = enteredText + ' ' + enteredProduct;
              annmountAndProductToSend = amountAndProduct;
          }
          else setAmount('')
          
  
      }
  
      function confirmProduct()
      {
        
          props.navigation.navigate('Main',{input:enteredProduct});
          setEnteredProduct('');
          setAmount('');
          
      }
  
      function returnToMainScreen()
      {
          props.navigation.navigate('Main')
      }
  
      return(
          
         
              &lt;TouchableWithoutFeedback onPress = {() =&gt; {Keyboard.dismiss();}}&gt;
              &lt;View style = {styles.inputContainer}&gt;
                  &lt;Card style = {styles.screen} &gt;
                      &lt;TextInput blurOnSubmit autoCapitalize=&quot;none&quot;
                      placeholder=&quot;Nazwa przedmiotu&quot; 
                      style={styles.input} 
                      onChangeText={enteredProductHandler} //1.onChangeText pobiera wpisany text i wysyła do goalInputHandler
                      value={enteredProduct}
                      /&gt;
                       &lt;TextInput keyboardType = &quot;number-pad&quot; 
                      placeholder=&quot;Ilość&quot; 
                      style={styles.input} 
                      onChangeText={amountHandler} //1.onChangeText pobiera wpisany text i wysyła do goalInputHandler
                      value={amount}
                      /&gt;
                  
                 &lt;View style = {styles.buttonContainer}&gt;
                     &lt;View style = {styles.button}&gt;
                  &lt;Button color = {colors.accent} title = 'Dodaj' onPress = {confirmProduct}/&gt;
                  &lt;/View&gt;
                  &lt;View style = {styles.button}&gt;
                  &lt;Button title = 'Wyjdź' color = {colors.accent} onPress={returnToMainScreen}/&gt;
                  &lt;/View&gt;
                  &lt;/View&gt;
                  &lt;/Card&gt; 
                  
               &lt;/View&gt;
               &lt;/TouchableWithoutFeedback&gt;
        
          
      );
  };
  
  
  
  const styles = StyleSheet.create({
  
      screen:
      {
          justifyContent:'center',
          alignItems:'center',
          
      },
  
      inputContainer:{
  
          flex: 0.5, 
          justifyContent:'center',
          alignItems:'center'
        },
  
        input:{
          height:30,
          borderBottomColor: 'grey',
          borderBottomWidth: 1,
          marginVertical: 13,
          
        },
  
        buttonContainer:{
            flexDirection:'row',
            alignItems: 'center',
            justifyContent: 'space-between' ,
            width: '60%'
        },
        
        button:{
            width:'40%',
           
        }
    });
  
    export default AddingScreen;
  </code></pre>
  <p>And here is the screen, where i'm passing this data (input) to add it to VirtualizedList:</p>
  <pre><code>import { StatusBar } from 'expo-status-bar';
  import React, {useState, useContext} from 'react';
  import { 
    StyleSheet, 
    View, 
    Button, 
    VirtualizedList,
    Alert,
  } from 'react-native';
  
  
  
  import GoalItem from'../components/Goalitem';
  import Header from '../components/Header';
  import colors from '../constants/colors';
  
  
  
  type Props={
    navigation:any
  }
  
  //setProducts([...products,{id: Math.random().toString(), value: props.navigation.getParam('input')}]); 
  
  const MainScreen = (props:Props) =&gt;{
  
   
    const [products, setProducts]  = useState&lt;any&gt;([]);
    const [didAddInput, setDidAddInput] = useState&lt;boolean&gt;(false);
    const [amont, setAmount] = useState&lt;any&gt;([]);
  
   
  
    function addProduct(input:string,oneadd:boolean){
  
     setDidAddInput(oneadd);
  
    if(didAddInput === true)
    {
      setProducts([...products,{id: Math.random().toString(), value: input}]); 
      return products;
    }
    setDidAddInput(false)
  
    };
    
    
  
  
    function removeGoalHandler(goalId:any):void
    {
      setProducts((courseGoals: any[]) =&gt; 
      {
        return courseGoals.filter((goal:any) =&gt; goal.id !== goalId);
      });
    };
  
  
    function deleteListAlert():void
    {
      if(products.length &gt;0)
      {
        Alert.alert(
          'Lista zostanie wyczyszczona!',
          'Czy aby na pewno chcesz wyczyścić liste?',
          [{text: 'Tak', style: 'destructive', onPress: deleteList},
           {text: 'Nie', style: 'cancel'}]);
      }
  
      else{
        Alert.alert(
          'Lista jest pusta.',
          'W liście nie ma żadnych przedmiotów.',
          [{text: 'Powrót', style: 'cancel'}]);
  
      }
  
    }
  
    function deleteList()
    {
      setProducts('')
    }
  
    function count():number
    {
      return 50;
    }
  
  
  
    return (
      
      &lt;View style = {styles.screen}&gt;
        &lt;Header title=&quot;Lista zakupów&quot;/&gt;
        &lt;VirtualizedList 
          keyExtractor={(item:any, index) =&gt; item.id}
          //data ={addProduct(value)} 
          getItem = {addProduct(JSON.stringify(props.navigation.getParam('input')),true)}
          getItemCount = {count}
          renderItem ={itemData =&gt; (
            &lt;GoalItem 
            id = {itemData.item.id} 
            onDelete = {removeGoalHandler} 
            title = {itemData.item.value} 
  
            /&gt;
          )}
        /&gt;
  
  &lt;View style = {styles.buttonPosition}&gt;
        &lt;View style = {styles.button1}&gt;
            &lt;Button color = {colors.accent} title = &quot;WYCZYŚĆ&quot; onPress={deleteListAlert}/&gt;
          &lt;/View&gt;
          &lt;View style = {styles.button}&gt;
            &lt;Button color = {colors.accent} title=&quot;+&quot; onPress = {() =&gt; {
              props.navigation.navigate('Adding')
            }}/&gt;
         &lt;/View&gt;
        &lt;/View&gt;
        &lt;/View&gt;
        
    );
  
   
  }
  
  const styles = StyleSheet.create({
    screen:{
     flex:1,
     backgroundColor: 'white',
    },
  
    button:{
      width: 40,
    },
  
    button1:{
      width: 90,
    },
  
    buttonPosition:{
      padding:15,
      alignItems: 'stretch',
      justifyContent: 'space-between',
      flexDirection:'row',
      backgroundColor: colors.primary,
    },
  
  });
  
  export default MainScreen;
  
  
  
  
  
  </code></pre>
  <p>So my data is here:</p>
  <pre><code>getItem = {addProduct(JSON.stringify(props.navigation.getParam('input')),true)}
  </code></pre>
  <p>I put it in console.log and it's sent right, but i've got a problem with adding it to</p>
  <pre><code>const [products, setProducts]  = useState&lt;any&gt;([]);
  </code></pre>
  <p>(products is my array of values)</p>
  <p>I try to put a second useState to avoid multiple adding by changing state to false after adding but it changes nothing, i've got an error &quot;Component Exception: Too many re-renders&quot;, also try to use globalState but it doesn't work. Maybe there is another and better way to change the state with input data, thanks for help :)</p>