In this article, we are going to build a chat application using React JS. We are going to use Microsoft Teams as our chat platform.
First, we need to create a new project. We can do this by running the following command in our terminal:
npx create-react-app chat-app
Once the project has been created, we need to install the Microsoft Teams React SDK. We can do this by running the following command in our terminal:
npm install @microsoft/teams-react
Once the SDK has been installed, we need to add it to our project. We can do this by running the following command in our terminal:
npm add @microsoft/teams-react
Now, we need to create our chat component. We can do this by running the following command in our terminal:
touch Chat.js
We can now add the following code to our Chat.js file:
import React, { Component } from ‘react’; import { Button, Panel, TextInput, Team } from ‘@microsoft/teams-react’; export default class Chat extends Component { constructor(props) { super(props); this.state = { messages: [], user: null, team: null }; } componentDidMount() { this.getTeam(); } getTeam() { if (this.state.team === null) { this.setState({ team: Team.get() }); } } sendMessage(message) { this.setState({ messages: [message], user: null, team: null }); } handleInput(event) { if (event.target.value) { this.sendMessage(event.target.value); } } render() { return (
Chat
- {this.state.messages.map((message, index) => { return (
-
{message.from}{message.date}{message.text}