parse-community/parse-react

Feature request: enabled option

rshov opened this issue · 3 comments

rshov commented

I'd like to request a feature. It would be helpful to disable a query from running in some situations, until a condition is met.

I think adding an option enabled to go alongside enableLocalDatastore and enableLiveQuery would do the trick.

The problem that I have is when using parse-react-ssr with Next.js (but using client-side only), when I use the next/router to get a document id from the query string, it can be undefined for a short time while the page loads. So I end up having to check if the id is not null:

  const router = useRouter()
  const projectId = router.query.projectId
  const query = new Parse.Query('Project')

  if (projectId) {
    query.get(projectId)
  }

  const { results } = useParseQuery(query)

If there was an enabled flag, then I could do this:

  const { results } = useParseQuery(query, { enabled: !!projectId })

Another way this flag could be helpful is to allow a query to be dependent on another. For example, if we first needed to lookup the project before we could look up something dependent on the project.

What do you think?
Thanks!

I think it makes sense and we should add this flag. Would you be willed to open a PR with that?

rshov commented

Yes I can take a shot at it, give me a couple weeks. Thanks

rshov commented

I just submitted a pull request #72 . Please check it over when you can. Thanks!