In this article, we will walk through a simple example of a real-time chat application built with React hooks and Socket.io.
Some use cases for web applications require real-time updates from the server. One such example is a chat application. If you have multiple users chatting together you could refresh updates from the server, but there is a cleaner solution that will push updates from the server to the UI. Sockets make this possible. And lucky for us developers there is a library called Socket.IO that makes working with sockets simple.
In this article, we will walk through a simple example of a real-time chat application built with React hooks and Socket.io. This example app will provide a quick guide for setting up a new real-time application and I will provide all of the source code.
For the example project that we will be building, we will need to create a Node.js server and a React UI. To get started create a new folder and initialize a new project so that we can install our dependencies before we start development.
Note: You can install create-react-app globally, but if you run with npx instead it will automatically grab the latest version and you don’t have to install it.