Below is the return statement of abc.tsx
return (
<ImageBackground
source={require("../assets/images/abc.png")}
style={styles.bg}
>
<CardStack>
{
byTest(globalThis.test).map((item) => (
<Card key={item.id}>
<CardItemForSwiper
image={item.image}
name={item.name}
description={item.description}
/>
</Card>
)
)
}
</CardStack>
</ImageBackground>
);
If you observe the above statement, we have something called byTest(globalThis.test) which is responsible to get an array of data from some other ts file and it looks like below
export const byTest = (test: string) => {
const filData = data.filter((rawData) => {
return rawData.test== test
})
if (filData.length > 0) {
globalThis.test= test
}
return new Promise((resolve)=>{return resolve(filData)})
}
Problem:
Now my problem is, byTest(globalThis.test) call is getting triggered multiple times because of multiple renders... so I have decided to use useEffect to get the data and pass it to this return.
So could you please help me with the best possible solution for this? Not just useEffect, as I am new to react Native I am looking for the best possible solution if useEffect hook doesn't fit
Goal:
byTest(globalThis.test) call should be triggered only once even if we have multiple renders by abc.tsx