From dabb98eb7d5e512ed2ddb76271beed24bd934b71 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 6 Feb 2019 19:52:26 +0300 Subject: useState, useEffect --- vnext/src/components/UserInfo.js | 90 ++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 50 deletions(-) (limited to 'vnext/src') diff --git a/vnext/src/components/UserInfo.js b/vnext/src/components/UserInfo.js index 3c4ffab3..d772d76e 100644 --- a/vnext/src/components/UserInfo.js +++ b/vnext/src/components/UserInfo.js @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useState, useEffect } from 'react'; import PropTypes from 'prop-types'; import { Link } from 'react-router-dom'; @@ -12,59 +12,49 @@ import SearchBox from './SearchBox'; import './UserInfo.css'; -export default class UserInfo extends React.Component { - constructor(props) { - super(props); - this.state = { - user: { uname: props.user, uid: 0 } - }; - } - componentDidMount() { - info(this.state.user.uname).then(response => { - this.setState({ - user: response.data - }); - this.props.onUpdate && this.props.onUpdate(response.data); +export default function UserInfo(props) { + const [user, setUser] = useState({ uname: props.user, uid: 0 }); + useEffect(() => { + info(user.uname).then(response => { + setUser(response.data); + props.onUpdate && props.onUpdate(response.data); }); - } - render() { - const { user } = this.state; - return ( - <> -
- -
Was online recently
-
-
-
- { - user.uid > 0 && - <> - - PM + }); + return ( + <> +
+ +
Was online recently
+
+
+
+ { + user.uid > 0 && + <> + + PM - - Recommendations + + Recommendations - - Photos + + Photos - { - user.read && - I read: {user.read.length} - } - My readers: {user.readers ? user.readers.length : 0} - { - user.statsMyBL && - My blacklist: {user.statsMyBL} - } - - } -
- {this.props.children} - - ); - } + { + user.read && + I read: {user.read.length} + } + My readers: {user.readers ? user.readers.length : 0} + { + user.statsMyBL && + My blacklist: {user.statsMyBL} + } + + } +
+ {props.children} + + ); } UserInfo.propTypes = { -- cgit v1.2.3