-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add derived channel usage example to 'docs/react.md'
- Loading branch information
1 parent
d8f3cd6
commit 63adfc4
Showing
1 changed file
with
23 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -139,6 +139,29 @@ const { channel } = useChannel({ channelName: "your-channel-name", options: { .. | |
}); | ||
``` | ||
|
||
[Subscription filters](https://ably.com/docs/channels#filter-subscribe) are also supported: | ||
|
||
```javascript | ||
const deriveOptions = { filter: 'headers.email == `"[email protected]"` || headers.company == `"domain"`' } | ||
const { channel } = useChannel({ channelName: "your-derived-channel-name", options: { ... }, deriveOptions }, (message) => { | ||
... | ||
}); | ||
``` | ||
|
||
Please note that attempts to publish to a derived channel (the one created or retrieved with a filter expression) will fail. In order to send messages to the channel called _"your-derived-channel-name"_ from the example above, you will need to create another channel instance without a filter expression. | ||
|
||
```javascript | ||
const channelName = "your-derived-channel-name"; | ||
const options = { ... }; | ||
const deriveOptions = { filter: 'headers.email == `"[email protected]"` || headers.company == `"domain"`' } | ||
const callback = (message) => { ... }; | ||
|
||
const { channel: readOnlyChannelInstance } = useChannel({ channelName, options, deriveOptions }, callback); | ||
const { channel: readWriteChannelInstance } = useChannel({ channelName, options }, callback); // NB! No 'deriveOptions' passed here | ||
|
||
readWriteChannelInstance.publish("test-message", { text: "message text" }); | ||
``` | ||
|
||
--- | ||
|
||
### usePresence | ||
|