This is a code repository for the corresponding YouTube video. In this tutorial we are going to build and deploy a real time chat application. Covered topics: React.js, Node.js, Express.js, and Socket.io.
import React, { useState, useEffect } from "react";
import queryString from 'query-string';
import io from "socket.io-client";
import TextContainer from '../TextContainer/TextContainer';
import Messages from '../Messages/Messages';
import InfoBar from '../InfoBar/InfoBar';
import Input from '../Input/Input';
How can I send Images to other people?
import React, { useState, useEffect } from "react"; import queryString from 'query-string'; import io from "socket.io-client";
import TextContainer from '../TextContainer/TextContainer'; import Messages from '../Messages/Messages'; import InfoBar from '../InfoBar/InfoBar'; import Input from '../Input/Input';
import './Chat.css';
const ENDPOINT = 'localhost:5000';
let socket;
const Chat = ({ location }) => { const [name, setName] = useState(''); const [room, setRoom] = useState(''); const [users, setUsers] = useState(''); const [message, setMessage] = useState(''); const [messages, setMessages] = useState([]); const [file, setFile] = useState('');
useEffect(() => { const { name, room } = queryString.parse(location.search);
}, [ENDPOINT, location.search]);
useEffect(() => { socket.on('message', message => { setMessages(messages => [ ...messages, message ]); });
}, []);
const sendMessage = (event) => { event.preventDefault();
}
function selectFile(e) { setMessage(e.target.files[0].name); setFile(e.target.files[0]); }
return (
); }
export default Chat;
This is the code that I've modified.