Here is my code -
const [time, setTime] = useState('')
const getRefresh = () => {
pageContext.refreshList()
var today = new Date()
var currentTime = today.getHours() + ':' + today.getMinutes() + ':' + today.getSeconds();
setTime(currentTime)
}
<div className="bttn-layout">
<LastRefreshed getRefresh={time}/>
<Button label="Refresh" onClick={e =>getRefresh()} />
</div>
Here is the code in my 'LastRefreshed' component -
const LastRefreshed = (props) => {
return (
<div>
<p>Last Refreshed: {props.time} </p>
</div>
)
}
export default LastRefreshed;
Ideally, when the refresh button is clicked, it will call the getRefresh function which updates a list on my home page as well as passing the current timestamp to 'time' state. This state is then used by my 'LastRefreshed' function and will therefore show the last refreshed timestamp. At the moment, the code above is not working. The getRefresh function is definitely being called however I am struggling with getting the time to show in my LastRefreshed component. I am wondering if it's because the state is not properly updating? Any help appreciated!