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