From d64fc4be0130b7dfb91fdb3e05fccad380253abc Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 25 Feb 2019 02:17:19 +0300 Subject: Users using hooks --- vnext/src/components/Users.js | 42 +++++++++++++++--------------------------- 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/vnext/src/components/Users.js b/vnext/src/components/Users.js index 2bab6de1..522aaa30 100644 --- a/vnext/src/components/Users.js +++ b/vnext/src/components/Users.js @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useState } from 'react'; import PropTypes from 'prop-types'; @@ -14,32 +14,20 @@ export function Readers({ user, ...rest }) { return ; } -class Users extends React.Component { - constructor(props) { - super(props); - this.state = { - user: {} - }; - } - updateUser = (user) => { - this.setState({ - user: user - }); - } - render() { - return ( - - - { - this.state.user[this.props.prop] && - this.state.user[this.props.prop].map(user => - - ) - } - - - ); - } +function Users(props) { + const [user, setUser] = useState(props.user); + return ( + + + { + user[props.prop] && + user[props.prop].map(user => + + ) + } + + + ); } -- cgit v1.2.3