Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6827c800f1 | |||
| 5ee1bf2eee | |||
| c137c644e3 |
Generated
+9
-1256
File diff suppressed because it is too large
Load Diff
+1
-4
@@ -4,13 +4,12 @@
|
|||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
"lint": "eslint .",
|
"lint": "eslint .",
|
||||||
"preview": "vite preview"
|
"preview": "vite preview"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"info": "^1.0.0",
|
|
||||||
"react": "^19.1.0",
|
"react": "^19.1.0",
|
||||||
"react-dom": "^19.1.0"
|
"react-dom": "^19.1.0"
|
||||||
},
|
},
|
||||||
@@ -23,8 +22,6 @@
|
|||||||
"eslint-plugin-react-hooks": "^5.2.0",
|
"eslint-plugin-react-hooks": "^5.2.0",
|
||||||
"eslint-plugin-react-refresh": "^0.4.19",
|
"eslint-plugin-react-refresh": "^0.4.19",
|
||||||
"globals": "^16.0.0",
|
"globals": "^16.0.0",
|
||||||
"sass": "^1.99.0",
|
|
||||||
"sass-embedded": "^1.99.0",
|
|
||||||
"vite": "^6.3.5"
|
"vite": "^6.3.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+48
-19
@@ -1,29 +1,58 @@
|
|||||||
import styles from './styles/App.module.scss'
|
import React from 'react'
|
||||||
import React, { useState, useCallback } from 'react'
|
|
||||||
|
|
||||||
function CounterButton({label, onClick}) {
|
class RandomUser extends React.Component {
|
||||||
return (
|
constructor(props) {
|
||||||
<button onClick={onClick} className={styles.counter_button}>{label}</button>
|
super(props)
|
||||||
)
|
this.state = { user: {} }
|
||||||
}
|
}
|
||||||
function CounterDisplay({value}) {
|
|
||||||
return (<div className={styles.counter_display}>
|
componentDidMount() {
|
||||||
Значение счетчика: <b>{value}</b>
|
fetch('https://randomuser.me/api')
|
||||||
</div>)
|
.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 App() {
|
function App() {
|
||||||
const [counter,setCounter] = useState(0);
|
const [showClock, setShowClock] = React.useState(true);
|
||||||
|
|
||||||
const increment = () => setCounter(prev => prev + 1);
|
|
||||||
const decrement = () => setCounter(prev => prev - 1);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<h2>Практика по созданию счетчика с колбэками</h2>
|
<h1>Домашнее задание: жизненый цикл</h1>
|
||||||
<CounterButton label="Увеличить" onClick={increment} />
|
<button onClick={()=> setShowClock(!showClock)}>
|
||||||
<CounterButton label="уменьшить" onClick={decrement} />
|
{showClock ? 'Скрыть часы' : 'Показать часы' }
|
||||||
<CounterDisplay value={counter} />
|
</button>
|
||||||
|
{showClock && <RandomUser />}
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-3
@@ -1,10 +1,8 @@
|
|||||||
import { StrictMode } from 'react'
|
import { StrictMode } from 'react'
|
||||||
import { createRoot } from 'react-dom/client'
|
import { createRoot } from 'react-dom/client'
|
||||||
|
// удаляем import './index.css'
|
||||||
import App from './App.jsx'
|
import App from './App.jsx'
|
||||||
|
|
||||||
createRoot(document.getElementById('root')).render(
|
createRoot(document.getElementById('root')).render(
|
||||||
<StrictMode>
|
|
||||||
<App />
|
<App />
|
||||||
</StrictMode>
|
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
.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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user