-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: docusaurus setup for v6 release (#2721)
* docs: docusaurus setup for v6 release * docs: docusaurus setup for v6 release * docs: fix vale issues * docs: add v5 docs to v5 folder
- Loading branch information
Showing
518 changed files
with
20,419 additions
and
14 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
34 changes: 34 additions & 0 deletions
34
...rus/reactnative_versioned_docs/version-5.x.x/additional-resources/libraries.mdx
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
id: libraries | ||
sidebar_position: 2 | ||
title: Libraries | ||
--- | ||
|
||
### [React Navigation Docs](https://reactnavigation.org/docs/getting-started/) | ||
|
||
Our tutorials, guides and sample apps are all using React Navigation. We recommend using it in | ||
order to provide better support for all the use cases displayed. | ||
|
||
### [Gesture Handler Docs](https://docs.swmansion.com/react-native-gesture-handler/docs/) | ||
|
||
React Native Gesture Handler is used inside of our SDK on our channels and messages lists. Also used | ||
on our gallery, chat buttons, and reactions overlay. | ||
|
||
### [Markdown Lib Docs](https://github.com/andangrd/react-native-markdown-package) | ||
|
||
React Native Markdown Package is used to render markdown on our messages. | ||
|
||
### [Reanimated Lib Docs](https://docs.swmansion.com/react-native-reanimated/docs) | ||
|
||
React Native Reanimated is used to create our own beautiful custom animations in our gallery, attachment picker, | ||
message actions/reactions and loading indicators/skeletons. | ||
|
||
### [Day.js Docs](https://day.js.org/docs/en/installation/installation) | ||
|
||
We are using Day.js to manipulate, customize, parse and display dates through the app. | ||
You may want to use it when creating you own custom components. | ||
|
||
### [React Native SVG](https://github.com/react-native-svg/react-native-svg) | ||
|
||
React Native SVG is one of our peer dependencies. We use it to render icons and a couple of small indicators | ||
through the app. |
44 changes: 44 additions & 0 deletions
44
...saurus/reactnative_versioned_docs/version-5.x.x/additional-resources/stream.mdx
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
--- | ||
id: stream-additional-resources | ||
sidebar_position: 1 | ||
title: Stream Additional Resources | ||
--- | ||
|
||
### [Demos](https://github.com/GetStream/react-native-samples) | ||
|
||
Stream Chat for React Native has multiple examples in the repository. | ||
In addition we have "cloned" some popular UIs to help demonstrate the flexibility of the SDK. | ||
|
||
### [JavaScript Client](https://getstream.io/chat/docs/javascript/?language=javascript) | ||
|
||
Stream Chat for React Native uses the Stream Chat JS client under the hood for most interactions with the backend. | ||
The client documentation covers a wide range of interactions that can be performed, not all of these are used within | ||
the Stream Chat for React Native SDK but can be integrated within your own app as required. | ||
|
||
### [API Tutorial](https://getstream.io/chat/get_started/) | ||
|
||
To help you get acquainted with the Stream Chat JS client we have an easy to follow tutorial on our website. | ||
This is a great primer for using the client directly and can also help you understand how the Stream Chat for | ||
React Native SDK if functioning under the hood. | ||
|
||
### [Stream Chat JS Basic Guide](https://github.com/GetStream/javascript-beginner-guide) | ||
|
||
> ### Internal Articles | ||
- [Stream Chat Glossary](https://getstream.zendesk.com/hc/en-us/articles/1500007212082-Stream-Chat-Glossary) | ||
|
||
- [Stream Chat Success Checklist](https://getstream.zendesk.com/hc/en-us/articles/1500007673721-Stream-Chat-Success-Checklist) | ||
|
||
- [React - Customizing Message Actions](https://getstream.zendesk.com/hc/en-us/articles/1500008025241--Customizing-Message-Actions-in-React-Chat) | ||
|
||
- [Stream Webhooks](https://getstream.zendesk.com/hc/en-us/articles/1500006478421-How-can-I-use-the-Stream-Webhook-to-send-customers-emails-based-on-Chat-events-) | ||
|
||
- [Stream Rate limits](https://getstream.zendesk.com/hc/en-us/articles/360056792833-Rate-limits-and-HTTP-429-Errors) | ||
|
||
- [Stream API → Client → Server](https://getstream.zendesk.com/hc/en-us/articles/360061669873-How-do-the-Chat-Client-Server-Stream-API-communicate-with-each-other-) | ||
|
||
- [Stream Chat Moderation](https://getstream.zendesk.com/hc/en-us/articles/360041455753) | ||
|
||
- [Stream User Roles and Permissions](https://getstream.zendesk.com/hc/en-us/articles/360053064274-User-Roles-and-Permission-Policies-Chat) | ||
|
||
- [Stream `queryChannels` filters](https://getstream.zendesk.com/hc/en-us/articles/360057461213-Filters-for-queryChannels-Chat) |
21 changes: 21 additions & 0 deletions
21
...rsioned_docs/version-5.x.x/additional-resources/technologies_and_techniques.mdx
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- | ||
id: technologies-and-techniques | ||
sidebar_position: 3 | ||
title: Technologies & Techniques | ||
--- | ||
|
||
### [Typescript Generics](https://www.typescriptlang.org/docs/handbook/2/generics.html) | ||
|
||
Our SDK is written in Typescript and heavily uses generics in order to allow users to use custom data and | ||
still have decent typing support. | ||
|
||
### [React Context](https://reactjs.org/docs/context.html) | ||
|
||
We rely on multiple contexts in our SDK to access components, functions, and data. | ||
Context also allows you as a developer to override our defaults for many of these throughout the SDK. | ||
Understanding how to draw upon values in context is important to customizing the SDK for your own needs. | ||
|
||
### [React Hooks](https://reactjs.org/docs/hooks-intro.html) | ||
|
||
We use/expose a bunch of our component's hooks so users can use them in order to replicate some behaviour/data | ||
parsing when creating custom components. Understanding how to work with hooks can come in very handy. |
Binary file added
BIN
+623 KB
...e_versioned_docs/version-5.x.x/assets/basics/hello-stream-chat/channel_list.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+669 KB
..._versioned_docs/version-5.x.x/assets/basics/hello-stream-chat/message_input.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+680 KB
...e_versioned_docs/version-5.x.x/assets/basics/hello-stream-chat/message_list.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+458 KB
...native_versioned_docs/version-5.x.x/assets/basics/hello-stream-chat/summary.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+623 KB
...tnative_versioned_docs/version-5.x.x/assets/basics/hello-stream-chat/thread.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.45 MB
...ersioned_docs/version-5.x.x/assets/basics/upgrading-from-v3/gallery_after_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.12 MB
...ersioned_docs/version-5.x.x/assets/basics/upgrading-from-v3/gallery_after_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.49 MB
...ersioned_docs/version-5.x.x/assets/basics/upgrading-from-v3/gallery_after_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.47 MB
...rsioned_docs/version-5.x.x/assets/basics/upgrading-from-v3/gallery_before_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.15 MB
...rsioned_docs/version-5.x.x/assets/basics/upgrading-from-v3/gallery_before_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.46 MB
...rsioned_docs/version-5.x.x/assets/basics/upgrading-from-v3/gallery_before_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+333 KB
...ioned_docs/version-5.x.x/assets/basics/upgrading-from-v3/pin_message_action.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+320 KB
...versioned_docs/version-5.x.x/assets/basics/upgrading-from-v3/pinned_message.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+315 KB
...oned_docs/version-5.x.x/assets/basics/upgrading-from-v3/scroll_view_warning.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.62 MB
...tive_versioned_docs/version-5.x.x/assets/basics/upgrading-from-v3/slow_mode.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+209 KB
...ioned_docs/version-5.x.x/assets/customization/custom-components/date_header.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+213 KB
..._docs/version-5.x.x/assets/customization/custom-components/name_date_header.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+213 KB
...d_docs/version-5.x.x/assets/customization/custom-components/new_date_header.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+211 KB
...ed_docs/version-5.x.x/assets/customization/custom-components/no_date_header.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+96.4 KB
...versioned_docs/version-5.x.x/assets/customization/typescript/explicit_types.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+83.5 KB
...tive_versioned_docs/version-5.x.x/assets/customization/typescript/inference.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+22.7 KB
...s/version-5.x.x/assets/guides/audio-support/audio-attachment-upload-preview.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+17.4 KB
...e_versioned_docs/version-5.x.x/assets/guides/audio-support/audio-attachment.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+92.4 KB
...d_docs/version-5.x.x/assets/guides/audio-support/audio-recorder-lock-button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+91.2 KB
..._docs/version-5.x.x/assets/guides/audio-support/audio-recording-in-progress.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+17.1 KB
...oned_docs/version-5.x.x/assets/guides/audio-support/audio-recording-preview.jpg
Oops, something went wrong.
Binary file added
BIN
+38.1 KB
...ve_versioned_docs/version-5.x.x/assets/guides/audio-support/start-recording.png
Oops, something went wrong.
Binary file added
BIN
+36.7 KB
...ersioned_docs/version-5.x.x/assets/guides/blocking-users/blocked-users-list.png
Oops, something went wrong.
Binary file added
BIN
+515 KB
...ioned_docs/version-5.x.x/assets/guides/custom-channel-list/load_more_button.png
Oops, something went wrong.
Binary file added
BIN
+177 KB
...ned_docs/version-5.x.x/assets/guides/custom-message-actions/message_actions.png
Oops, something went wrong.
Binary file added
BIN
+196 KB
..._docs/version-5.x.x/assets/guides/custom-message-actions/my_message_actions.png
Oops, something went wrong.
Binary file added
BIN
+2.07 MB
...on-5.x.x/assets/guides/custom-message-input/native_attachment_picker_step_1.png
Oops, something went wrong.
Binary file added
BIN
+1.61 MB
...on-5.x.x/assets/guides/custom-message-input/native_attachment_picker_step_2.png
Oops, something went wrong.
Binary file added
BIN
+452 KB
...cs/version-5.x.x/assets/guides/custom-thread-list/custom-thread-list-step-1.png
Oops, something went wrong.
Binary file added
BIN
+408 KB
...cs/version-5.x.x/assets/guides/custom-thread-list/custom-thread-list-step-2.png
Oops, something went wrong.
Binary file added
BIN
+373 KB
...cs/version-5.x.x/assets/guides/custom-thread-list/custom-thread-list-step-3.png
Oops, something went wrong.
Binary file added
BIN
+299 KB
...cs/version-5.x.x/assets/guides/custom-thread-list/custom-thread-list-step-4.png
Oops, something went wrong.
Binary file added
BIN
+826 KB
...ersion-5.x.x/assets/guides/debug-using-flipper-plugin/flipper_desktop_guide.png
Oops, something went wrong.
Binary file added
BIN
+897 KB
...s/guides/debug-using-flipper-plugin/flipper_stream_chat_react_native_banner.png
Oops, something went wrong.
Binary file added
BIN
+689 KB
...versioned_docs/version-5.x.x/assets/guides/deeplinking/xcode-info-url-types.png
Oops, something went wrong.
Binary file added
BIN
+572 KB
...ed_docs/version-5.x.x/assets/guides/deeplinking/xcode-signing-capabilitites.png
Oops, something went wrong.
Binary file added
BIN
+382 KB
...ersioned_docs/version-5.x.x/assets/guides/live-location-sharing/chat-screen.png
Oops, something went wrong.
Binary file added
BIN
+769 KB
...sioned_docs/version-5.x.x/assets/guides/live-location-sharing/detail-screen.png
Oops, something went wrong.
Binary file added
BIN
+204 KB
...ersioned_docs/version-5.x.x/assets/guides/moderation/bounced-message-action.png
Oops, something went wrong.
Binary file added
BIN
+16.8 KB
...ative_versioned_docs/version-5.x.x/assets/guides/moderation/bounced-message.png
Oops, something went wrong.
Binary file added
BIN
+333 KB
..._versioned_docs/version-5.x.x/assets/guides/moderation/moderation-dashboard.png
Oops, something went wrong.
Binary file added
BIN
+445 KB
...tive_versioned_docs/version-5.x.x/assets/guides/native-image-picker/options.png
Oops, something went wrong.
Binary file added
BIN
+6.94 KB
...ve_versioned_docs/version-5.x.x/assets/guides/performance/channel_settings.jpeg
Oops, something went wrong.
Binary file added
BIN
+155 KB
...d_docs/version-5.x.x/assets/guides/push-notifications/v2/chat_overview_page.png
Oops, something went wrong.
Binary file added
BIN
+108 KB
...ion-5.x.x/assets/guides/push-notifications/v2/firebase_notifications_toggle.png
Oops, something went wrong.
Binary file added
BIN
+199 KB
...oned_docs/version-5.x.x/assets/ui-components/channel-list/loading_indicator.png
Oops, something went wrong.
Binary file added
BIN
+257 KB
...rsioned_docs/version-5.x.x/assets/ui-components/channel-list/visual_guide_1.png
Oops, something went wrong.
Binary file added
BIN
+320 KB
...rsioned_docs/version-5.x.x/assets/ui-components/channel-list/visual_guide_2.png
Oops, something went wrong.
Binary file added
BIN
+566 KB
...ve_versioned_docs/version-5.x.x/assets/ui-components/channel/visual_guide_1.png
Oops, something went wrong.
Binary file added
BIN
+593 KB
...ve_versioned_docs/version-5.x.x/assets/ui-components/channel/visual_guide_2.png
Oops, something went wrong.
Binary file added
BIN
+752 KB
...ve_versioned_docs/version-5.x.x/assets/ui-components/channel/visual_guide_3.png
Oops, something went wrong.
Binary file added
BIN
+1.36 MB
...ve_versioned_docs/version-5.x.x/assets/ui-components/channel/visual_guide_4.png
Oops, something went wrong.
Binary file added
BIN
+193 KB
...versioned_docs/version-5.x.x/assets/ui-components/channel_preview_messenger.png
Oops, something went wrong.
Binary file added
BIN
+158 KB
...rsioned_docs/version-5.x.x/assets/ui-components/channel_preview_messenger_2.png
Oops, something went wrong.
Binary file added
BIN
+248 KB
...ned_docs/version-5.x.x/assets/ui-components/overlay-provider/visual_guide_1.png
Oops, something went wrong.
Binary file added
BIN
+421 KB
...ned_docs/version-5.x.x/assets/ui-components/overlay-provider/visual_guide_2.png
Oops, something went wrong.
Binary file added
BIN
+409 KB
...ned_docs/version-5.x.x/assets/ui-components/overlay-provider/visual_guide_3.png
Oops, something went wrong.
222 changes: 222 additions & 0 deletions
222
docusaurus/reactnative_versioned_docs/version-5.x.x/basics/client.mdx
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 |
---|---|---|
@@ -0,0 +1,222 @@ | ||
--- | ||
id: client | ||
sidebar_position: 5 | ||
title: Client | ||
--- | ||
|
||
import Tabs from '@theme/Tabs'; | ||
import TabItem from '@theme/TabItem'; | ||
|
||
Stream Chat for React Native uses the [Stream Chat client](https://github.com/GetStream/stream-chat-js) to connect to and communicate with the Stream API. | ||
|
||
The full [JavaScript client docs](https://getstream.io/chat/docs/javascript/?language=javascript) should be referenced for detailed information on directly using the client. | ||
|
||
## Setup | ||
|
||
To interact with the Stream Chat API you must create a client instance and connect to the API, usually as an authenticated user. | ||
|
||
### Instantiation | ||
|
||
The Stream Chat client, `StreamChat` is a dependency of `stream-chat-react-native` and can be imported from `stream-chat`. | ||
To create a client instance you can call `getInstance` on the client and provide and API key. | ||
|
||
```ts | ||
import { StreamChat } from 'stream-chat'; | ||
|
||
const client = StreamChat.getInstance('api_key'); | ||
``` | ||
|
||
:::caution | ||
|
||
**Usage of `StreamChat.getInstance()` available since [email protected].** | ||
|
||
<br /> | ||
This new Singleton pattern allows you to instantiate a unique StreamChat client, i.e create a StreamChat instance and | ||
retrieve it wherever you need it on your app to perform API calls. After calling it once, any following <code> | ||
getInstance | ||
</code> call will return the initial StreamChat instance. This will prevent you from accidentally creating multiple | ||
StreamChat instances, opening multiple WebSockets, and driving up your concurrent connections unnecessarily. | ||
<br /> | ||
<br /> | ||
|
||
Stream Chat is backward compatible. Users can continue using <code>new StreamChat()</code> if desired. | ||
|
||
<br /> | ||
|
||
```ts | ||
const client = new StreamChat('api_key'); | ||
``` | ||
|
||
Calling <code>new StreamChat()</code> repeatedly will create new copies of the client and in turn new WebSocket connections when <code>connectUser</code> is called. | ||
If you are using <code>new StreamChat()</code> you need to be vigilant about your use to ensure you are not creating multiple WebSocket connections unnecessarily. | ||
|
||
::: | ||
|
||
### Connecting a User | ||
|
||
To connect a user a the `connectUser` function should be called and provided with the user object and `user_token`. | ||
The `user_token` is typically sent from your back end when a user is authenticated. | ||
|
||
```ts | ||
await client.connectUser( | ||
{ | ||
id: 'testUser', | ||
name: 'Test User', | ||
}, | ||
'user_token', | ||
); | ||
``` | ||
|
||
It is recommended to not repeatedly call `connectUser` unnecessarily, multiple calls to `connectUser` will result in warnings, and attempting to call `connectUser` before disconnecting a current user will throw an Error. | ||
|
||
## UI Components | ||
|
||
The Stream Chat for React Native UI components handle most interactions with the client for you after connecting with an authenticated user. | ||
|
||
### Providing the Client to the UI | ||
|
||
To provide the client to the UI components you simply provide the client instance as the prop `client` to the `Chat` component. | ||
|
||
```tsx | ||
import { StreamChat } from 'stream-chat'; | ||
import { Chat } from 'stream-chat-react-native'; | ||
|
||
const client = StreamChat.getInstance('api_key'); | ||
|
||
export const Screen = () => <Chat client={client}>{/** App components */}</Chat>; | ||
``` | ||
|
||
The Stream Chat for React Native UI components then handle interacting with the client internally by accessing the client via [`context`](https://reactjs.org/docs/context.html). | ||
|
||
:::note | ||
|
||
If you are customizing certain components or functionality you may have to interact with the client as well. | ||
You can access the client provided to the `Chat` component internally via the `useChatContext`. | ||
|
||
<br /> | ||
|
||
```ts | ||
import { useChatContext } from 'stream-chat-react-native'; | ||
|
||
const { client } = useChatContext(); | ||
``` | ||
|
||
::: | ||
|
||
### Using UI Functions | ||
|
||
The UI provides a number of functions that interact with the client while keeping the UI state in sync using `context`. | ||
The [contexts section](../contexts/attachment-picker-context.mdx) details what functions are accessible. | ||
When customizing your application you should ensure you are utilizing the correct functions to keep the UI state up to date. | ||
|
||
The `sendMessage` function for instance, provided by `useMessageInputContext`, is not the same as the `sendMessage` function found directly on a `channel` in the client. | ||
Therefore calling `channel.sendMessage(messageData)` will not result in a message optimistically showing in the UI, or a failed send state, instead the message will not show until it is returned by the server. | ||
|
||
:::caution | ||
|
||
You should not assume any function directly called on the client will result in a UI update. | ||
The UI state is managed internally by the components and `context`, most client interactions require an event returned by the server to update the UI. | ||
|
||
::: | ||
|
||
## Accessing the Client Instance | ||
|
||
There are multiple ways to access the client instance throughout your application. | ||
[As mentioned](#providing-the-client-to-the-ui) you can access the `client` via `useChatContext` when inside the `Chat` component. | ||
This works well if you can wrap your entire application in a single `Chat` component and have the `StreamChat` instance provided throughout your app via the internal `context`. | ||
But if you have multiple screens that contain `Chat` components where a client instance is necessary you will need to access the shared instance in other ways. | ||
|
||
You can store the client in a [`context`](https://reactjs.org/docs/context.html) you create yourself. | ||
Create your own custom class that provides it. | ||
Or using the Singleton structure you can call `getInstance` when required to always be returned the current instance if one exists, or create a new one otherwise. | ||
|
||
:::warning | ||
|
||
Do not create and connect multiple instances using `new StreamChat()`, this will result in multiple `StreamChat` instances and opening multiple WebSocket connections. | ||
|
||
::: | ||
|
||
## Direct Interaction | ||
|
||
There may be some direct interaction with the client that is required for your application. | ||
Referring to the [full documentation](https://getstream.io/chat/docs/javascript/?language=javascript) is suggested for detailed information on client functionality. | ||
Common interactions with the client used in conjunction with the Stream Chat for React Native components have been included for convenience. | ||
|
||
### Creating a Channel | ||
|
||
A channel must be initialized with either an `id` or a list of members for the channel. | ||
If you provide a list of members an `id` will be auto-generated on backend for the channel. | ||
|
||
:::note | ||
|
||
You can't add or remove members from channel created using a list of members. | ||
|
||
::: | ||
|
||
<Tabs | ||
defaultValue='channelId' | ||
values={[ | ||
{ label: 'Channel Id', value: 'channelId' }, | ||
{ label: 'Members List', value: 'members' }, | ||
]} | ||
> | ||
<TabItem value='channelId'> | ||
|
||
```ts | ||
/** | ||
* Channel created using a channel id | ||
*/ | ||
const channel = client.channel(channel_type, 'channel_id', { | ||
name: 'My New Channel', | ||
}); | ||
``` | ||
|
||
</TabItem> | ||
<TabItem value='members'> | ||
|
||
```ts | ||
/** | ||
* Channel created using a members list | ||
*/ | ||
const channel = client.channel(channel_type, { | ||
members: ['userOne', 'userTwo'] | ||
name: 'My New Channel', | ||
}); | ||
``` | ||
|
||
</TabItem> | ||
</Tabs> | ||
|
||
To create a channel on the server you must call `create` or `watch` on a new channel instance. | ||
`create` will create the channel while `watch` will both create the channel and subscribe the client to updates on the channel. | ||
|
||
<Tabs | ||
defaultValue='watch' | ||
values={[ | ||
{ label: 'watch', value: 'watch' }, | ||
{ label: 'create', value: 'create' }, | ||
]} | ||
> | ||
<TabItem value='watch'> | ||
|
||
```ts | ||
await channel.watch(); | ||
``` | ||
|
||
</TabItem> | ||
<TabItem value='create'> | ||
|
||
```ts | ||
await channel.create(); | ||
``` | ||
|
||
</TabItem> | ||
</Tabs> | ||
|
||
### Disconnecting a User | ||
|
||
To disconnect a user you can call `disconnect` on the client. | ||
|
||
```ts | ||
await client.disconnectUser(); | ||
``` |
Oops, something went wrong.