From 6827c800f1ef071f03b745e1b562eccc72fea8e7 Mon Sep 17 00:00:00 2001 From: Laktionov Anton Date: Tue, 2 Jun 2026 20:23:09 +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=81?= =?UTF-8?q?=20=D1=84=D0=BE=D1=82=D0=BE=D0=B3=D1=80=D0=B0=D1=84=D0=B8=D0=B5?= =?UTF-8?q?=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.jsx | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index 601c297..506afdc 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,30 +1,44 @@ import React from 'react' -class Clock extends React.Component { +class RandomUser extends React.Component { constructor(props) { super(props) - this.state = { time: new Date().toLocaleTimeString() } + this.state = { user: {} } } componentDidMount() { - this.timerId = setInterval(()=>{ - this.setState({ time: new Date().toLocaleTimeString() }) - }, 1000); - console.log('Таймер смонтирован') + 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() { - clearInterval(this.timerId) console.log('Компонент таймера размонтирован') } render() { return
-

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

+ {this.state.user && + this.state.user.name && + ( + <> +

{this.state.user.name.first} {this.state.user.name.last}

+ + + + ) + }
} } @@ -34,11 +48,11 @@ function App() { return ( <> -

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

+

Домашнее задание: жизненый цикл

- {showClock && } + {showClock && } ) }