From 5ee1bf2eeef0fe664f2c35ab4a6ba9299c5f9ca7 Mon Sep 17 00:00:00 2001 From: Laktionov Anton Date: Tue, 2 Jun 2026 19:51:47 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=D0=B8=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BC=D0=BF=D0=BE=D0=BD=D0=B5=D0=BD=D1=82=20=D1=87?= =?UTF-8?q?=D0=B0=D1=81=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.jsx | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index 021d8b6..601c297 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,39 +1,44 @@ import React from 'react' -class MyComponent extends React.Component { +class Clock extends React.Component { constructor(props) { super(props) - this.state = { count: 0 } + this.state = { time: new Date().toLocaleTimeString() } } componentDidMount() { - console.log('Компонент смонтирован') + this.timerId = setInterval(()=>{ + this.setState({ time: new Date().toLocaleTimeString() }) + }, 1000); + console.log('Таймер смонтирован') } componentDidUpdate(prevProps,prevState) { console.log('Компонент обнвлен') - if(prevState.count !== this.state.count) { - console.log('Состояние изменилось') - } } componentWillUnmount() { - console.log('Компонент будет размонтирован') + clearInterval(this.timerId) + console.log('Компонент таймера размонтирован') } render() { return
- Привет мир! {this.props.name} {this.state.count} - +

Текущее время: {this.state.time}

} } function App() { + const [showClock, setShowClock] = React.useState(true); + return ( <> -

Hello, React!

- +

Жизненный цикл компонента часов

+ + {showClock && } ) }