Query results are empty during reload()
rshov opened this issue · 2 comments
It seems that when reload() is called on a query, the results become null until the query returns.
I think it would be much better if the results kept their existing value while the query is fetching results. This allows for a more seamless experience in the UI.
Take the below example:
const query = new Parse.Query('Project')
query.get(projectId)
const { results, reload } = useParseQuery(query)
const project = (results && results.length) ? results[0] : null
// If the project is empty then show a blank page while it loads
if (!project) return null
const updateProject = async () => {
// Make some updates to the project
project.add('locations', 'another')
await project.save()
reload()
}
return (
<div>
<Button onClick={updateProject}>
Update Project
</Button>
{ // List the project locations
project.get('locations').map(location => <div>{location}</div>)
}
</div>
)
In this example, I am updating the Project when the button is clicked, and reloading the project object.
Right now, the page will go blank while the project reloads.
But if the project kept it's value during reload, then it would just get updated when the new project object returned.
I hope this makes sense. I'm happy to discuss more if helpful.
Thanks!
Hi. Thanks for raising the issue. Is your live query turned one? In this case, you don't need to call the reload() function. The objects will be automatically updated.
Thanks @davimacedo , you're right that does solve my problem. I think it would still make sense to make the change for reload() for other use cases, but I'll close this issue. Thank you!