-
SCSS/SASS
The definitive guide to SCSS -
Javascript
W3Schools JavaScript Tutorial
W3Schools JavaScript Reference
MDN JavaScript -
Text Editor Google Search: popular Text Editor
I used Visual Studio Code.
If you have no basic knowledge, you won't be able to go to the next step.
This is my chatroom. >>>>> JS Bin on jsbin.com
Google Search: Create React App
npx create-react-app my-app
The "my-app" is your project folder name.
In this video, we are using "react-socketio-chatroom".
npx create-react-app react-socketio-chatroom
Now, we go to the folder "react-socketio-chatroom"
cd react-socketio-chatroom
Check files.
In linux/macOS, we using command ls
linux command ls
In windows, we using command dir
Windows-commands dir
sass
sass-loader
Use NPM(Node Package Manager) install sass and sass-loader
npm install -d sass sass-loader
npm run start
React offical doc: Your First Component
Class Name
JavaScript Arrow Function
Keeping list items in order with key
Type 1: React Form Submitting Forms - Multiple Input Fields
- Add the "onSubmit" attribute to the "
<form>
" and create the corresponding handler function. - Get the event target, make sure the target is "
<form>
". - Get FormData.
- Transform formData to jsonObj
- Avoid empty message.
- Clean textarea.
- Passing Props Function.
- Keydown Event.
- Add the "onClick" attribute to the "
<form>
" and create the corresponding handler function. - Use your "ref objects" by passing them as the ref attribute to both the and <textarea> elements.
- Get 'user' data and 'message' data.
- Create jsonObj.
- Avoid empty message.
- Clean textarea
- Passing Props Function.
- Keydown Event.
If you pass a function as nextState, it will be treated as an updater function. It must be pure, should take the pending state as its only argument, and should return the next state. React will put your updater function in a queue and re-render your component. During the next render, React will calculate the next state by applying all of the queued updaters to the previous state.
React Hooks - useRef - Manipulating the DOM with a ref HTML Element Scroll Height HTML Element Scroll To
SocketIO > Offical Documentation
For Server Side npm install socket.io
doc
For Client Side npm install socket.io-client
doc
Basically, you need to install the following packages:
npm install express cors socket.io socket.io-client
express, cors, socket.io
is for server
After a client connection is created, the 'socketIO' server will start listening to the following events:
socket.on('joinRoom', ******
socket.on('leaveRoom',
socket.on('new message', (msgObj) => {
// When a client sends the 'new message' event, the server will broadcast the message to all members of the room.
io.to(msgObj.roomId).emit('server message', msgObj);
});
You can get server file in here
We use React Hooks - useState to store socket connection.
- After the socket variable has been set, we need to register other events.
- Edit send message function
- Testing message sending in a different window.
In this moment, we run two process of nodeJS in our computer
npm run start
means "run the application in development mode."npm run start:server
mean "run the server".
We need to bring all these steps together and make a production build.
Use:
npm run build
and
npm run start:server
again
We can access the chatroom at http://localhost:8080.
If you wish to access the chatroom, you can replace the word "localhost" with the IP address of the computer running the server.
To find the IP address of your LAN network, you can use the 'ifconfig' command (Mac/Linux). For windows, you can use the 'ipconfig' command.
Full source code at here https://github.com/yesseecity/React-Socketio-Chatroom/tree/main