Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4a01e01

Browse files
lifecycle method in react class based component added and update some codebase
1 parent c7e518d commit 4a01e01

File tree

46 files changed

+3881
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+3881
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
dist
12+
dist-ssr
13+
*.local
14+
15+
# Editor directories and files
16+
.vscode/*
17+
!.vscode/extensions.json
18+
.idea
19+
.DS_Store
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Vite + React</title>
8+
</head>
9+
<body>
10+
<div id="root"></div>
11+
<script type="module" src="/src/main.jsx"></script>
12+
</body>
13+
</html>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "01-class-component",
3+
"private": true,
4+
"version": "0.0.0",
5+
"type": "module",
6+
"scripts": {
7+
"dev": "vite",
8+
"build": "vite build",
9+
"preview": "vite preview"
10+
},
11+
"dependencies": {
12+
"react": "^18.2.0",
13+
"react-dom": "^18.2.0"
14+
},
15+
"devDependencies": {
16+
"@types/react": "^18.0.26",
17+
"@types/react-dom": "^18.0.9",
18+
"@vitejs/plugin-react": "^3.0.0",
19+
"vite": "^4.0.0"
20+
}
21+
}
Lines changed: 1 addition & 0 deletions
Loading[フレーム]
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#root {
2+
max-width: 1280px;
3+
margin: 0 auto;
4+
padding: 2rem;
5+
text-align: center;
6+
}
7+
8+
.logo {
9+
height: 6em;
10+
padding: 1.5em;
11+
will-change: filter;
12+
}
13+
.logo:hover {
14+
filter: drop-shadow(0 0 2em #646cffaa);
15+
}
16+
.logo.react:hover {
17+
filter: drop-shadow(0 0 2em #61dafbaa);
18+
}
19+
20+
@keyframes logo-spin {
21+
from {
22+
transform: rotate(0deg);
23+
}
24+
to {
25+
transform: rotate(360deg);
26+
}
27+
}
28+
29+
@media (prefers-reduced-motion: no-preference) {
30+
a:nth-of-type(2) .logo {
31+
animation: logo-spin infinite 20s linear;
32+
}
33+
}
34+
35+
.card {
36+
padding: 2em;
37+
}
38+
39+
.read-the-docs {
40+
color: #888;
41+
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import React from "react"
2+
import ReactDOM from "react-dom"
3+
4+
/*
5+
6+
Challenge:
7+
1. Convert all 3 components to be class-based
8+
2. Fix the small bug
9+
10+
*/
11+
12+
// #1
13+
class App extends React.Component {
14+
render() {
15+
return (
16+
<div>
17+
<Header username="bobziroll" />
18+
<Greeting />
19+
</div>
20+
)
21+
}
22+
}
23+
24+
// #2
25+
class Header extends React.Component {
26+
render() {
27+
return (
28+
<header>
29+
<p>Welcome, {this.props.username}!</p>
30+
</header>
31+
)
32+
}
33+
}
34+
35+
// #3
36+
// Hint: any "display logic" can be placed inside the `render`
37+
// method before the `return` statement
38+
class Greeting extends React.Component {
39+
render() {
40+
const date = new Date()
41+
const hours = date.getHours()
42+
let timeOfDay
43+
44+
if (hours < 12) {
45+
timeOfDay = "morning"
46+
} else if (hours >= 12 && hours < 17) {
47+
timeOfDay = "afternoon"
48+
} else {
49+
timeOfDay = "night"
50+
}
51+
return (
52+
<h1>Good {timeOfDay} to you, sir or madam!</h1>
53+
)
54+
}
55+
}
56+
57+
ReactDOM.render(<App />, document.getElementById("root"))
58+
59+
60+
// **********************************************************************************************************
61+
62+
63+
// import React from "react"
64+
// import ReactDOM from "react-dom"
65+
66+
// /*
67+
68+
// Challenge:
69+
// 1. Convert all 3 components to be class-based
70+
// 2. Fix the small bug
71+
72+
// */
73+
74+
// // #1
75+
// function App() {
76+
// return (
77+
// <div>
78+
// <Header />
79+
// <Greeting />
80+
// </div>
81+
// )
82+
// }
83+
84+
// // #2
85+
// function Header(props) {
86+
// return (
87+
// <header>
88+
// <p>Welcome, {props.username}!</p>
89+
// </header>
90+
// )
91+
// }
92+
93+
// // #3
94+
// // Hint: any "display logic" can be placed inside the `render`
95+
// // method before the `return` statement
96+
// function Greeting() {
97+
// const date = new Date()
98+
// const hours = date.getHours()
99+
// let timeOfDay
100+
101+
// if (hours < 12) {
102+
// timeOfDay = "morning"
103+
// } else if (hours >= 12 && hours < 17) {
104+
// timeOfDay = "afternoon"
105+
// } else {
106+
// timeOfDay = "night"
107+
// }
108+
// return (
109+
// <h1>Good {timeOfDay} to you, sir or madam!</h1>
110+
// )
111+
// }
112+
113+
// ReactDOM.render(<App />, document.getElementById("root"))
Lines changed: 1 addition & 0 deletions
Loading[フレーム]
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
:root {
2+
font-family: Inter, Avenir, Helvetica, Arial, sans-serif;
3+
font-size: 16px;
4+
line-height: 24px;
5+
font-weight: 400;
6+
7+
color-scheme: light dark;
8+
color: rgba(255, 255, 255, 0.87);
9+
background-color: #242424;
10+
11+
font-synthesis: none;
12+
text-rendering: optimizeLegibility;
13+
-webkit-font-smoothing: antialiased;
14+
-moz-osx-font-smoothing: grayscale;
15+
-webkit-text-size-adjust: 100%;
16+
}
17+
18+
a {
19+
font-weight: 500;
20+
color: #646cff;
21+
text-decoration: inherit;
22+
}
23+
a:hover {
24+
color: #535bf2;
25+
}
26+
27+
body {
28+
margin: 0;
29+
display: flex;
30+
place-items: center;
31+
min-width: 320px;
32+
min-height: 100vh;
33+
}
34+
35+
h1 {
36+
font-size: 3.2em;
37+
line-height: 1.1;
38+
}
39+
40+
button {
41+
border-radius: 8px;
42+
border: 1px solid transparent;
43+
padding: 0.6em 1.2em;
44+
font-size: 1em;
45+
font-weight: 500;
46+
font-family: inherit;
47+
background-color: #1a1a1a;
48+
cursor: pointer;
49+
transition: border-color 0.25s;
50+
}
51+
button:hover {
52+
border-color: #646cff;
53+
}
54+
button:focus,
55+
button:focus-visible {
56+
outline: 4px auto -webkit-focus-ring-color;
57+
}
58+
59+
@media (prefers-color-scheme: light) {
60+
:root {
61+
color: #213547;
62+
background-color: #ffffff;
63+
}
64+
a:hover {
65+
color: #747bff;
66+
}
67+
button {
68+
background-color: #f9f9f9;
69+
}
70+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react'
2+
import ReactDOM from 'react-dom/client'
3+
import App from './App'
4+
import './index.css'
5+
6+
ReactDOM.createRoot(document.getElementById('root')).render(
7+
<React.StrictMode>
8+
<App />
9+
</React.StrictMode>,
10+
)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { defineConfig } from 'vite'
2+
import react from '@vitejs/plugin-react'
3+
4+
// https://vitejs.dev/config/
5+
export default defineConfig({
6+
plugins: [react()],
7+
})

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /