Skip to content

Allow to conditionally use the hook useThreads #2039

Open
@elias-bananaz

Description

@elias-bananaz

Is your feature request related to a problem? Please describe.

We fetch threads according to some metadata, in this case an index. The problem is that until some operations are finished this index can be undefined. We still want to render the rest of the component, but threads should be null at this stage.

  const { threads } = useThreads({
    query: { metadata: { index: index } },
  });

Describe the solution you'd like

We don't want to send an undefined query or a default index since this would return either all data or unrelated data.

We think there should be a way to make the return of threads conditional, so we don't have to make an unneeded fetch if the metadata is not in a valid stage.

Additional context

Unfortunately, because of React's rule of hooks it's just not possible to do something like:

  const { threads } = index !== undefined ?
     useThreads({
        query: { metadata: { index: index } },
     })
     : { threads: [] };

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestFeature requested by the community

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions