The Context:
A hook is defined and returns an object that contains the timestamp of the last time a file was modified.
I calculate the difference from the timestamp until now to show the user how long it was been since they have last saved.
const StageFooter = (props) => {
const [, , meta] = useMetadata("Tenant Setup Data", "setupData")
return (
<StageControls>
<div id="footer-start"></div>
<SavingBlock key={meta?.modified}>
{`Last saved ${
meta.modified !== undefined ? formatDistanceToNow(meta.modified) : " "
} ago`}
</SavingBlock>
<div id="footer-end"></div>
</StageControls>
)
}
export default StageFooter
The Problem:
The calculated difference from the timestamp until now does not update in real-time. For example, it would say "Last saved 10 minutes ago" but after a couple of minutes has passed the string still remains the same. It would only update if the user navigates away from the page then back or if the user refreshes the page.
With all this in mind, I'm basically looking to rerender the component every time a minute has passed so that the value is updated in real-time.
Thanks for your time!