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
Sometimes you don't want to subscribe to a channel until another bit of data is available. It would be nice if you allowed
useChannelto acceptundefined,null, orfalseas a conditional to wait to subscribe. Similar to howuseSWRdoes it.For instance:
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