# useEffect side effect

**URL:** <https://forum.codewithmosh.com/t/useeffect-side-effect/12377>\
**Category:** React Native\
**Created:** [May 11, 2022, 11:49am UTC](https://forum.codewithmosh.com/t/useeffect-side-effect/12377 "2022-05-11T11:49:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![axlbj](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/axlbj/32/3469_2.png) [@axlbj](https://forum.codewithmosh.com/u/axlbj)\
**Post date:** [May 11, 2022, 11:49am UTC](https://forum.codewithmosh.com/t/useeffect-side-effect/12377/1 "2022-05-11T11:49:47Z")

</div>

is anybody experienced the same way?

```auto
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

```

```auto
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

---

<div class="post-metadata">

**Author:** ![eelsholz](https://avatars.discourse-cdn.com/v4/letter/e/439d5e/32.png) [@eelsholz](https://forum.codewithmosh.com/u/eelsholz)\
**Post date:** [May 12, 2022, 1:47am UTC](https://forum.codewithmosh.com/t/useeffect-side-effect/12377/2 "2022-05-12T01:47:45Z")

</div>

According to [this SO answer](https://stackoverflow.com/questions/53715465/can-i-set-state-inside-a-useeffect-hook#answer-54923969) “using `setState` inside `useEffect` will create an infinite loop that most likely you don’t want to cause.”

---

<div class="post-metadata">

**Author:** ![axlbj](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/axlbj/32/3469_2.png) [@axlbj](https://forum.codewithmosh.com/u/axlbj)\
**Post date:** [May 12, 2022, 3:11am UTC](https://forum.codewithmosh.com/t/useeffect-side-effect/12377/3 "2022-05-12T03:11:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![eelsholz](https://avatars.discourse-cdn.com/v4/letter/e/439d5e/32.png) [@eelsholz](https://forum.codewithmosh.com/u/eelsholz)\
**Post date:** [May 14, 2022, 1:16am UTC](https://forum.codewithmosh.com/t/useeffect-side-effect/12377/4 "2022-05-14T01:16:30Z")

</div>

Instead of using `useEffect`, can you pass the the data via props? Maybe something like what’s described in [this SO article](https://stackoverflow.com/questions/53942539/how-to-pass-data-between-react-native-screens)?
