I want to change the value of state [time] every second when a button is pressed. I have the code below, but unfortunately the code doesn't work.Do you have any suggestion on how can I handle this issue ?
Many thanks !
import React,{useState} from 'react';import {View,Text,StyleSheet,TouchableOpacity} from 'react-native';import { AntDesign } from '@expo/vector-icons';const TimeButton = () =>{ const [time,setTime] = useState(10) let intervalId:any = null; return(<View style={styles.container}><TouchableOpacity><AntDesign name="caretleft" size={24} color="black" /></TouchableOpacity><Text>{time}</Text><TouchableOpacity onPressIn={() => { intervalId = setInterval(setTime(time+1), 1000) }} onPressOut={() => clearInterval(intervalId)}><AntDesign name="caretright" size={59} color="black" /></TouchableOpacity></View> )}const styles = StyleSheet.create({ container:{ flex:1, flexDirection:'row', alignItems:'center', justifyContent:"center" }})export default TimeButton;