Skip to content

Commit

Permalink
feat: add derived channel usage example to 'docs/react.md'
Browse files Browse the repository at this point in the history
  • Loading branch information
rustworthy committed Nov 15, 2023
1 parent d8f3cd6 commit 63adfc4
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions docs/react.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 63adfc4

Please sign in to comment.