When the text value is logged with a button press, it displays the current value (what I'm expecting). The issue is when I use a setInterval to do the same, it logs every previous value. Is this intentional? If it is, how can I avoid this. Thanks.
import React from 'react';
import {Text, View, Button} from 'react-native';
function showText(text){
console.log(text);
}
export default function App() {
const [text,textHook] = React.useState("text not set");
// Log out text every second
setInterval(()=>{
showText(text); // Function repeats for every previous value with a setInterval
},1000);
return (
<View>
<Text>{text}</Text>
<Button
title="change text here"
onPress={()=>{
textHook("text is changed");
console.log(text); // Function works as expected with a button press
}}
/>
</View>
);
}