From 12515f925d8d4a4942484f1270c5c8fc0b1d37f8 Mon Sep 17 00:00:00 2001 From: Laktionov Anton Date: Thu, 28 May 2026 20:45:57 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=D0=B8=20?= =?UTF-8?q?=D1=82=D0=B0=D0=B9=D0=BC=D0=B5=D1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.jsx | 30 ++++++++++++++++++++++++++++-- src/main.jsx | 2 -- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index 7e35cc8..2a6b4ab 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -72,11 +72,37 @@ class MyComponent3 extends React.Component { } } } + +class Timer extends React.Component { + constructor(props) { + super(props); + this.state = { seconds: 0 } + } + + componentDidMount() { + console.log('Timer mounted'); + this.interval = setInterval(()=>{ + this.setState(prevState => ({seconds: prevState.seconds + 1})) + },1000); + } + + componentWillUnmount() { + console.log('Timer unmount'); + clearInterval(this.interval); + } + render() { + return

Прошло секунд: {this.state.seconds}

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

Hello, React!

- +

Таймер с классом

+ + {show && } ) } diff --git a/src/main.jsx b/src/main.jsx index 950e96a..7e925e8 100644 --- a/src/main.jsx +++ b/src/main.jsx @@ -4,7 +4,5 @@ import { createRoot } from 'react-dom/client' import App from './App.jsx' createRoot(document.getElementById('root')).render( - - )