refactor: rewrite collabWrapper to remove TDZs and simplify (#2834)

This commit is contained in:
David Luzar 2021-01-25 10:47:35 +01:00 committed by GitHub
parent 03f6d9c783
commit 0a0be839b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 312 additions and 264 deletions

View file

@ -1,5 +1,6 @@
import clsx from "clsx";
import React, { useCallback, useEffect, useState } from "react";
import React, { useEffect } from "react";
import { useCallbackRefState } from "../hooks/useCallbackRefState";
import { t } from "../i18n";
import useIsMobile from "../is-mobile";
import { KEYS } from "../keys";
@ -8,14 +9,6 @@ import { back, close } from "./icons";
import { Island } from "./Island";
import { Modal } from "./Modal";
const useRefState = <T,>() => {
const [refValue, setRefValue] = useState<T | null>(null);
const refCallback = useCallback((value: T) => {
setRefValue(value);
}, []);
return [refValue, refCallback] as const;
};
export const Dialog = (props: {
children: React.ReactNode;
className?: string;
@ -24,7 +17,7 @@ export const Dialog = (props: {
title: React.ReactNode;
autofocus?: boolean;
}) => {
const [islandNode, setIslandNode] = useRefState<HTMLDivElement>();
const [islandNode, setIslandNode] = useCallbackRefState<HTMLDivElement>();
useEffect(() => {
if (!islandNode) {