Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

212
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!