Skip to content

useChannel(false) to prevent eager channel connection #44

Description

@iamthesiz

Sometimes you don't want to subscribe to a channel until another bit of data is available. It would be nice if you allowed useChannel to accept undefined, null, or false as a conditional to wait to subscribe. Similar to how useSWR does it.
For instance:

const Messenger = () => {
  const my = useMe()
  const channelURL = my.username && `/api/messages/${my.username}`
  const channel = useChannel(channelURL)
  useEvent(channel, eventType, data => {
  })
}

In the above example, this prevents sending a subscription request from happening until we get my.username. Otherwise we would be subscribing to channel /api/messages/undefined

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions