Fix mention hook order (#214)

This commit is contained in:
Szymon Szlachtowicz 2022-02-02 12:58:15 +01:00 committed by GitHub
parent 51b85b5b49
commit 2e028c468e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 4 deletions

View File

@ -25,17 +25,16 @@ export function Mention({ id, setMentioned, className }: MentionProps) {
const [showMenu, setShowMenu] = useState(false); const [showMenu, setShowMenu] = useState(false);
const identity = useIdentity(); const identity = useIdentity();
if (!contact) return <>{id}</>;
useEffect(() => { useEffect(() => {
if (identity) { if (identity && contact) {
if (contact.id === utils.bufToHex(identity.publicKey)) setMentioned(true); if (contact.id === utils.bufToHex(identity.publicKey)) setMentioned(true);
} }
}, [contact.id, identity]); }, [contact, identity]);
const ref = useRef(null); const ref = useRef(null);
useClickOutside(ref, () => setShowMenu(false)); useClickOutside(ref, () => setShowMenu(false));
if (!contact) return <>{id}</>;
return ( return (
<MentionBLock <MentionBLock
onClick={() => setShowMenu(!showMenu)} onClick={() => setShowMenu(!showMenu)}