Open platform to collect and prioritize feedback
refactor: migrate Hint to React Hooks (#788)
chagrialicfd7e24442d1
diff --git a/public/components/common/Hint.tsx b/public/components/common/Hint.tsxindex df24857f9..9e6a07e55 100644--- a/public/components/common/Hint.tsx+++ b/public/components/common/Hint.tsx@@ -1,6 +1,6 @@import "./Hint.scss";-import React from "react";+import React, { useState } from "react";import { FaTimes } from "react-icons/fa";import { cache } from "@fider/services";@@ -10,41 +10,24 @@ interface HintProps {condition?: boolean;}-interface HintState {- isClosed: boolean;-}--export class Hint extends React.Component<HintProps, HintState> {- private cacheKey: string | undefined;-- constructor(props: HintProps) {- super(props);- this.cacheKey = this.props.permanentCloseKey ? `Hint-Closed-${this.props.permanentCloseKey}` : undefined;- this.state = {- isClosed: this.cacheKey ? cache.local.has(this.cacheKey) : false- };- }+export const Hint: React.FC<HintProps> = props => {+ const cacheKey: string | undefined = props.permanentCloseKey ? `Hint-Closed-${props.permanentCloseKey}` : undefined;+ const [isClosed, setIsClosed] = useState<boolean>(cacheKey ? cache.local.has(cacheKey) : false);- private close = () => {- if (this.cacheKey) {- cache.local.set(this.cacheKey, "true");+ const close = () => {+ if (cacheKey) {+ cache.local.set(cacheKey, "true");}-- this.setState({- isClosed: true- });+ setIsClosed(true);};- public render() {- if (this.props.condition === false || this.state.isClosed) {- return null;- }-- return (- <p className="c-hint">- <strong>HINT:</strong> {this.props.children}- {this.cacheKey && <FaTimes onClick={this.close} className="close" />}- </p>- );+ if (props.condition === false || isClosed) {+ return null;}-}+ return (+ <p className="c-hint">+ <strong>HINT:</strong> {props.children}+ {cacheKey && <FaTimes onClick={close} className="close" />}+ </p>+ );+};