From c1fb8c74ff79c73b4621276f3c2a60c92bd6d05f Mon Sep 17 00:00:00 2001 From: Mihir Shah <48630359+MihirGH@users.noreply.github.com> Date: Thu, 27 Oct 2022 04:31:28 +0530 Subject: [PATCH] chore: convert Avatar component to functional component (#4204) (#4337) --- app/components/Avatar/Avatar.tsx | 46 +++++++++++++------------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/app/components/Avatar/Avatar.tsx b/app/components/Avatar/Avatar.tsx index 290a298d4..5d26fc8ff 100644 --- a/app/components/Avatar/Avatar.tsx +++ b/app/components/Avatar/Avatar.tsx @@ -1,8 +1,7 @@ -import { observable } from "mobx"; -import { observer } from "mobx-react"; import * as React from "react"; import styled from "styled-components"; import User from "~/models/User"; +import useBoolean from "~/hooks/useBoolean"; import placeholder from "./placeholder.png"; type Props = { @@ -16,35 +15,28 @@ type Props = { className?: string; }; -@observer -class Avatar extends React.Component { - @observable - error: boolean; +function Avatar(props: Props) { + const { src, icon, showBorder, ...rest } = props; - static defaultProps = { - size: 24, - }; + const [error, handleError] = useBoolean(false); - handleError = () => { - this.error = true; - }; - - render() { - const { src, icon, showBorder, ...rest } = this.props; - return ( - - - {icon && {icon}} - - ); - } + return ( + + + {icon && {icon}} + + ); } +Avatar.defaultProps = { + size: 24, +}; + const AvatarWrapper = styled.div` position: relative; `;