Compare commits

..

8 Commits

5 changed files with 1304 additions and 59 deletions
+1256 -9
View File
File diff suppressed because it is too large Load Diff
+4 -1
View File
@@ -4,12 +4,13 @@
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"dev": "vite",
"build": "vite build",
"lint": "eslint .",
"preview": "vite preview"
},
"dependencies": {
"info": "^1.0.0",
"react": "^19.1.0",
"react-dom": "^19.1.0"
},
@@ -22,6 +23,8 @@
"eslint-plugin-react-hooks": "^5.2.0",
"eslint-plugin-react-refresh": "^0.4.19",
"globals": "^16.0.0",
"sass": "^1.99.0",
"sass-embedded": "^1.99.0",
"vite": "^6.3.5"
}
}
+19 -48
View File
@@ -1,58 +1,29 @@
import React from 'react'
import styles from './styles/App.module.scss'
import React, { useState, useCallback } from 'react'
class RandomUser extends React.Component {
constructor(props) {
super(props)
this.state = { user: {} }
}
componentDidMount() {
fetch('https://randomuser.me/api')
.then(responce => responce.json())
.then(json => this.setState({ user: json.results[0] }));
console.log('смонтирован')
}
componentDidUpdate(prevProps,prevState) {
console.log(this.state);
console.log('Компонент обнвлен')
}
componentWillUnmount() {
console.log('Компонент таймера размонтирован')
}
render() {
return <div>
{this.state.user &&
this.state.user.name &&
(
<>
<h2>{this.state.user.name.first} {this.state.user.name.last}</h2>
<img src={this.state.user.picture.medium} />
<button onClick={() => {
console.log('Загружаем ... ')
fetch('https://randomuser.me/api')
.then(responce => responce.json())
.then(json => this.setState({ user: json.results[0] }));
}}>Загрузить нового</button>
</>
)
}
</div>
}
function CounterButton({label, onClick}) {
return (
<button onClick={onClick} className={styles.counter_button}>{label}</button>
)
}
function CounterDisplay({value}) {
return (<div className={styles.counter_display}>
Значение счетчика: <b>{value}</b>
</div>)
}
function App() {
const [showClock, setShowClock] = React.useState(true);
const [counter,setCounter] = useState(0);
const increment = () => setCounter(prev => prev + 1);
const decrement = () => setCounter(prev => prev - 1);
return (
<>
<h1>Домашнее задание: жизненый цикл</h1>
<button onClick={()=> setShowClock(!showClock)}>
{showClock ? 'Скрыть часы' : 'Показать часы' }
</button>
{showClock && <RandomUser />}
<h2>Практика по созданию счетчика с колбэками</h2>
<CounterButton label="Увеличить" onClick={increment} />
<CounterButton label="уменьшить" onClick={decrement} />
<CounterDisplay value={counter} />
</>
)
}
+3 -1
View File
@@ -1,8 +1,10 @@
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
// удаляем import './index.css'
import App from './App.jsx'
createRoot(document.getElementById('root')).render(
<StrictMode>
<App />
</StrictMode>
)
+22
View File
@@ -0,0 +1,22 @@
.container {
display:flex;
flex-direction: row;
border: 1px solid black;
border-radius: 5px;
margin-bottom: 10px;
p {
padding: 5px 10px;
}
}
.counter {
&_display{
border: 1px solid black;
border-width: 3px;
border-radius: 10px;
padding: 10px;
width: 300px;
}
&_button{
padding: 10px;
}
}