Skip to content

Commit 8120f89

Browse files
committed
Split into two examples
1 parent 55e25b0 commit 8120f89

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

README.md

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,46 @@ If you encounter any problems with `@talkjs/react`, please open an issue. If you
1919
- [React SDK reference docs](/Reference/React_SDK/Installation/)
2020
- [Team chat tutorial](https://talkjs.com/resources/how-to-use-talkjs-to-create-a-team-chat-with-channels/) and [example code](https://github.com/talkjs/talkjs-examples/tree/master/react/remote-work-demo)
2121

22-
## Example
22+
## Examples
2323

24-
The following example uses the [`Session`](/Reference/React_SDK/Components/Session/) and [`Chatbox`](/Reference/React_SDK/Components/Chatbox/) components from the React SDK to create a chatbox UI, and syncs a user and conversation with it with the JavaScript SDK.
24+
The following examples use the [`Session`](/Reference/React_SDK/Components/Session/) and [`Chatbox`](/Reference/React_SDK/Components/Chatbox/) components from the React SDK to create a chatbox UI.
2525

26-
Install both `@talkjs/react` and the [`talkjs` JavaScript package](https://www.npmjs.com/package/talkjs):
26+
For both examples, you'll first need to install both `@talkjs/react` and the [`talkjs` JavaScript package](https://www.npmjs.com/package/talkjs):
2727

2828
```sh
2929
npm install talkjs @talkjs/react
3030
# or
3131
yarn add talkjs @talkjs/react
3232
```
3333

34-
Then add the following code to your React app. Replace the `<APP_ID>` with your App ID from the **Settings** tab of the TalkJS dashboard:
34+
### Add an existing user and conversation
35+
36+
This example demonstrates how to create a TalkJS session with an existing user and view a chatbox UI with an existing conversation. We'll use a sample user and conversation that are already included in your [test environment](/Features/Environments/).
37+
38+
Add the following code to your React app. Replace the `<APP_ID>` with your test environment App ID from the **Settings** tab of the TalkJS dashboard:
39+
40+
```jsx
41+
import { Session, Chatbox } from "@talkjs/react";
42+
43+
function ChatComponent() {
44+
return (
45+
<Session appId="<APP_ID>" userId="sample_user_alice">
46+
<Chatbox
47+
conversationId="sample_conversation"
48+
style={{ width: "100%", height: "500px" }}
49+
></Chatbox>
50+
</Session>
51+
);
52+
}
53+
54+
export default ChatComponent;
55+
```
56+
57+
### Sync a user and conversation
58+
59+
This example demonstrates how to sync a user and conversation that you create with the JavaScript SDK.
60+
61+
Add the following code to your React app:
3562

3663
```jsx
3764
import { useCallback } from "react";
@@ -83,6 +110,8 @@ function ChatComponent() {
83110
export default ChatComponent;
84111
```
85112

113+
For more details and explanation, see our [getting started guide](/Getting_Started/Frameworks/React/).
114+
86115
## Contributing
87116

88117
This library is open-source and permissively licensed (MIT).

0 commit comments

Comments
 (0)