Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

214
Visualizações
Callback function leads to infinity loop error in react native

I am new to react native and simply can not find the reason for the infinity loop error I spent my last few hours with... Here is what is happening:

I have the following custom component

import { TouchableOpacity, StyleSheet, View, Text } from "react-native";
import { FontAwesome } from "@expo/vector-icons";

function AnswerContainer_CheckBox(props) {
  const [checked, setChecked] = useState(false);

const checkedHandler =()=>{
  if (checked == false) {
    setChecked(true);
  } else {
    setChecked(false);
  }
}
  return (
    <View>
      <TouchableOpacity
        onPress={() => {
         checkedHandler();
         props.true_1;
          }
        }
      >
        <View style={styles.mainContainer}>
          <View style={styles.icon}>
            <FontAwesome
              name={checked == true ? "check-square" : "square-o"}
              size={24}
              color={checked == true ? "#3787FF" : "#BFD3E5"}
            />
          </View>
          <Text style={styles.checkButtonText}>{props.title}</Text>
        </View>
      </TouchableOpacity>
    </View>
  );
}

I use that Component in my screen like this:


function myScreen(props) {

  const [true1, setTrue1] = useState(false);

  const setTrue_1_Handler = () => {
    switch (true1) {
      case false:
        setTrue1(true);
        alert("true");
        break;
      case true:
        setTrue1(false);
        break;
    }
  };

  return (
    <SafeAreaView>
      <AnswerContainer_CheckBox true_1={setTrue_1_Handler()} title="Test_1" />
      <AnswerContainer_CheckBox title="Test_2" />
      <AnswerContainer_CheckBox title="Test_3" />
    </SafeAreaView>
  );
}

Whenever I navigate to "myScreen", the infite loop error apperas and crashes the app - even though I didn't press that button yet.

Any ideas? I know the issue has come up a few times but I still didn't make it work (useEffect didn't help somehow...).

Thanks

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda