@100mslive/roomkit-react
Version:

40 lines (32 loc) • 882 B
text/mdx
import { Story } from '@storybook/addon-docs';
This will be received by everyone in the room.
```js
hmsActions.sendBroadcastMessage('hello everyone!'); // yes it's that simple 😉
```
```jsx
const ChatExample = () => {
const chats = useHMSStore(selectHMSMessages);
const actions = useHMSActions();
const [input, setInput] = useState('');
const sendMessage = (e: React.FormEvent) => {
e.preventDefault();
actions.sendBroadcastMessage(input);
setInput('');
};
return (
<div>
{chats.map(c => (
<div>{c.message}</div>
))}
<form onSubmit={sendMessage}>
<input value={input} onChange={e => setInput(e.target.value)} type="text" />
<button type="submit">Send</button>
</form>
</div>
);
};
```
<Story id="chat-broadcast-message--chat-story-example" />