const result = []; for (i = 0; i < 2 && i < ar.length; i++) { result.push( <> <Countdown dateObj = {ar[i].time} /> <TouchableOpacity onPress={()=>{ console.log("SENDING DATA", ar[i]); navigation.navigate("ChatInterface", {data: ar[i]}); }}> </TouchableOpacity> </> ); } ... return <>{result}</>;
I put everything inside a for loop so I can return them all at once later using `return <>{result}</>. However,
ar[i] is coming out as undefined. Even though the line above involving Countdown
works fine. I'm thinking it has something to do with the scope of the anonymous function inside TouchableOpacity. How can I get this to work?
没有评论:
发表评论