From 8264ffcb1d6e8737c713fd9ae6a4c5b43444ce50 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 25 Feb 2019 00:53:39 +0300 Subject: Contacts using hooks --- vnext/src/components/Contacts.js | 47 ++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 31 deletions(-) (limited to 'vnext/src') diff --git a/vnext/src/components/Contacts.js b/vnext/src/components/Contacts.js index bdbc5a01..f726f173 100644 --- a/vnext/src/components/Contacts.js +++ b/vnext/src/components/Contacts.js @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useEffect, useState } from 'react'; import { getChats } from '../api'; @@ -6,40 +6,25 @@ import { getChats } from '../api'; import Contact from './Contact.js'; import { ChatSpinner } from './Spinner'; -export default class Contacts extends React.Component { - constructor(props) { - super(props); - this.state = { - pms: [] - }; - } - componentDidMount() { - this.refreshChats(); - } - - refreshChats() { +export default function Contacts(props) { + const [pms, setPms] = useState([]); + useEffect(() => { getChats() .then(response => { - this.setState({ - isLoading: false, - pms: response.data.pms - }); + setPms(response.data.pms); }); - } - render() { - const { pms } = this.state; - return ( -