I am trying to get some data from the current user object which is stored in the database. I am doing this in a react useEffect, so it runs right when the component mounts. For some reason, the data that is read from Moralis.User.current() is outdated.
const getPreferredAddress = async () => {
if (!isInitialized && !isAuthenticated) return
const user = Moralis.User.current()
const address = user.get('PreferredAddress')
if (typeof address == 'undefined') return
// Set the address in the ui
document.getElementById('preferredAddress').value = address
setPreferredAddress(address)
}
Address is an old version of my address. If I look on the database, it’s a different value. But if I save my code while this component is already mounted, it will fetch the correct data. Is the user object being stored in local storage and defaulting to old values? How can I make sure that the data is fetched from the database so it is always accurate? thank you.