Skip to content

Commit 72044ce

Browse files
committed
Connect socket
1 parent 740ef8d commit 72044ce

File tree

11 files changed

+102
-85
lines changed

11 files changed

+102
-85
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
REACT_APP_API_URL=http://localhost:3000

README.md

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,68 @@
1-
[Typescript Cheatsheet](https://github.com/typescript-cheatsheets/react-typescript-cheatsheet#reacttypescript-cheatsheets).
1+
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
22

3-
[Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
3+
## Available Scripts
44

5-
[React documentation](https://reactjs.org/).
5+
In the project directory, you can run:
6+
7+
### `npm start`
8+
9+
Runs the app in the development mode.<br />
10+
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
11+
12+
The page will reload if you make edits.<br />
13+
You will also see any lint errors in the console.
14+
15+
### `npm test`
16+
17+
Launches the test runner in the interactive watch mode.<br />
18+
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
19+
20+
### `npm run build`
21+
22+
Builds the app for production to the `build` folder.<br />
23+
It correctly bundles React in production mode and optimizes the build for the best performance.
24+
25+
The build is minified and the filenames include the hashes.<br />
26+
Your app is ready to be deployed!
27+
28+
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
29+
30+
### `npm run eject`
31+
32+
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
33+
34+
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
35+
36+
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
37+
38+
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
39+
40+
## Learn More
41+
42+
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
43+
44+
To learn React, check out the [React documentation](https://reactjs.org/).
45+
46+
### Code Splitting
47+
48+
This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
49+
50+
### Analyzing the Bundle Size
51+
52+
This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
53+
54+
### Making a Progressive Web App
55+
56+
This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
57+
58+
### Advanced Configuration
59+
60+
This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration
61+
62+
### Deployment
63+
64+
This section has moved here: https://facebook.github.io/create-react-app/docs/deployment
65+
66+
### `npm run build` fails to minify
67+
68+
This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,13 @@
66
"@testing-library/jest-dom": "^5.9.0",
77
"@testing-library/react": "^10.0.6",
88
"@testing-library/user-event": "^11.0.0",
9-
"@types/bootstrap": "^4.5.0",
10-
"@types/jest": "^25.2.3",
11-
"@types/node": "^14.0.9",
12-
"@types/react": "^16.9.35",
13-
"@types/react-bootstrap": "^1.0.1",
14-
"@types/react-dom": "^16.9.8",
159
"bootstrap": "^4.5.0",
1610
"node-sass": "^4.14.1",
1711
"react": "^16.13.1",
1812
"react-bootstrap": "^1.0.1",
1913
"react-dom": "^16.13.1",
2014
"react-scripts": "3.4.1",
21-
"socket.io-client": "^2.3.0",
22-
"typescript": "~3.9.3"
15+
"socket.io-client": "^2.3.0"
2316
},
2417
"devDependencies": {
2518
"husky": "^4.2.5",
@@ -35,7 +28,7 @@
3528
"build": "react-scripts build",
3629
"test": "react-scripts test",
3730
"eject": "react-scripts eject",
38-
"lint": "eslint --max-warnings 0 --ext js,jsx,ts,tsx src"
31+
"lint": "eslint --max-warnings 0 --ext js,jsx src"
3932
},
4033
"eslintConfig": {
4134
"extends": "react-app"

src/App.jsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import React, { useEffect, useState } from 'react';
2+
import io from 'socket.io-client';
3+
4+
const App = () => {
5+
const [socket, setSocket] = useState(null);
6+
7+
useEffect(() => {
8+
setSocket(io(process.env.REACT_APP_API_URL));
9+
}, [setSocket]);
10+
11+
useEffect(
12+
() => () => {
13+
if (socket !== null) {
14+
socket.removeAllListeners();
15+
socket.close();
16+
}
17+
},
18+
[socket],
19+
);
20+
21+
if (!socket) {
22+
return <div>Loading...</div>;
23+
}
24+
25+
return <div>test</div>;
26+
};
27+
28+
export default App;

src/App.tsx

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/components/Counter.tsx

Lines changed: 0 additions & 37 deletions
This file was deleted.
File renamed without changes.

src/react-app-env.d.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/types/CounterProps.tsx

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)