Skip to content

Query results are empty during reload()  #55

Closed
@rshov

Description

@rshov

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions