0
Hello, people. I’m new to React-Native and I’m still learning some basic concepts.
My current problem is this:
I want to make a screen of newly searched items, so that when the user clicks to type in Textinput, it will click below the list of items he has previously searched for.
But I’m making a mistake Too many re-renders. React limits the number of renders to prevent an infinite loop
I’ve done a lot of research on what might cause the mistake, but I can’t get to a final denominator.
function SearchList(){
const [searchElement, setElement] = React.useState([]);
const navigation = useNavigation();
const valorDigitado = '';
const addItem = (valor) => {
setElement([ ...searchElement, {
text: {valor},
}])
}
return(
<SafeAreaView>
<View style={styles.container}>
<View style={styles.rowContainer}>
<View>
<TouchableOpacity onPress={() => navigation.navigate('Home')}>
<Feather name="chevron-left" size={25} color="#53565A" ></Feather>
</TouchableOpacity>
</View>
<View style={styles.searchBar}>
<View
style={{flexDirection:'row', justifyContent:'center', alignItems:'center'}}>
<Icon name="search" size={20} color="grey" />
<TouchableOpacity>
<TextInput
style={styles.Search}
editable={true}
value={valorDigitado}
placeholder={"Pesquisar"}
returnKeyType={'search'}
onSubmitEditing={setElement(valorDigitado)}
>
</TextInput>
</TouchableOpacity>
</View>
</View>
</View>
{/* <View>
<FlatList
data={searchElement}
renderItem={({item}) => {
return <Text>{item}</Text>
}}
/>
</View> */}
</View>
</SafeAreaView>
)
}`