useEffect side effect

is anybody experienced the same way?

useEffect (() => {
        setNoItems(count);
        setTitlex(title);
        if(operator==1 || operator==0){
            setMinusx(operator);
            setChecking(0);
        }
        if(operator==2 || operator==0){
            setPlusx(operator);
            setChecking(0);
        }
        setSelectedItem(checking);
        //all sets are props
        console.log("check "+checking);
    });//issue about this is that the last component in array cause a React app freeze
useEffect (() => {
        setNoItems(count);
        setTitlex(title);
        if(operator==1 || operator==0){
            setMinusx(operator);
            setChecking(0);
        }
        if(operator==2 || operator==0){
            setPlusx(operator);
            setChecking(0);
        }
        setSelectedItem(checking);
        //all sets are props
        console.log("check "+checking);
    },[count,operator,checking]);//this time I add dependency, issue about this is that the moment I click the component React app freeze

Any help would be appreciated! I am a newbie in hooks

According to this SO answer “using setState inside useEffect will create an infinite loop that most likely you don’t want to cause.”

1 Like

thanks for your answer sir. Can you suggest on how can I pass that value inside the useEffect to other screen. Since I’m trying to pass all the data from my component to CartScreen and vise versa.

Instead of using useEffect, can you pass the the data via props? Maybe something like what’s described in this SO article?