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 && } ) }