From d09194f05a372e3ed136aa288ae76cae8c1dc641 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Sun, 20 Jun 2021 18:15:13 -0700 Subject: Support live-reload and fallback Former-commit-id: c3f9d77391589b65951616a632af87107fba469f --- .../src/components/RenderCounter.tsx | 21 ++++++++++++ .../react-fast-refresh-test/src/components/app.tsx | 14 ++++++++ .../src/components/button.tsx | 38 +++------------------- .../src/components/new-comp.tsx | 3 -- 4 files changed, 40 insertions(+), 36 deletions(-) create mode 100644 demos/react-fast-refresh-test/src/components/RenderCounter.tsx create mode 100644 demos/react-fast-refresh-test/src/components/app.tsx delete mode 100644 demos/react-fast-refresh-test/src/components/new-comp.tsx (limited to 'demos/react-fast-refresh-test/src/components') diff --git a/demos/react-fast-refresh-test/src/components/RenderCounter.tsx b/demos/react-fast-refresh-test/src/components/RenderCounter.tsx new file mode 100644 index 000000000..ed2f00b56 --- /dev/null +++ b/demos/react-fast-refresh-test/src/components/RenderCounter.tsx @@ -0,0 +1,21 @@ +import React from "react"; + +export function RenderCounter({ name, children }) { + const counter = React.useRef(1); + return ( +
+
+
+ {name} rendered {counter.current++} times +
+
+ LAST RENDER:{" "} + {new Intl.DateTimeFormat([], { + timeStyle: "long", + }).format(new Date())} +
+
+
{children}
+
+ ); +} diff --git a/demos/react-fast-refresh-test/src/components/app.tsx b/demos/react-fast-refresh-test/src/components/app.tsx new file mode 100644 index 000000000..2edc02545 --- /dev/null +++ b/demos/react-fast-refresh-test/src/components/app.tsx @@ -0,0 +1,14 @@ +import * as React from "react"; +import { Button } from "./Button"; +import { RenderCounter } from "./RenderCounter"; +export function App() { + return ( + +
+

This is the root element

+ + +
+
+ ); +} diff --git a/demos/react-fast-refresh-test/src/components/button.tsx b/demos/react-fast-refresh-test/src/components/button.tsx index 3f55fae34..4c3388670 100644 --- a/demos/react-fast-refresh-test/src/components/button.tsx +++ b/demos/react-fast-refresh-test/src/components/button.tsx @@ -1,37 +1,9 @@ -import React from "react"; -import { NewComponent } from "./new-comp"; - -const Toast = () => { - const [baconyes, baconno] = useBacon(); - return
false
; -}; -const Button = ({ label, label2, onClick }) => { - const useCustomHookInsideFunction = (what, arr) => { - return [true, false]; - }; - const [on, setOn] = React.useState(false); - - React.useEffect(() => { - console.log({ on }); - }, [on]); - - // const [foo1, foo2] = useCustomHookInsideFunction(() => {}, [on]); +import { RenderCounter } from "./RenderCounter"; +export const Button = ({ children }) => { return ( -
- f -
{label}12
- -
+ +
{children}
+
); }; - -const Bacon = Button; - -export { Bacon, Bacon as Button }; - -const RefreshLike = () => {}; - -const useBacon = () => { - return [1, 8]; -}; diff --git a/demos/react-fast-refresh-test/src/components/new-comp.tsx b/demos/react-fast-refresh-test/src/components/new-comp.tsx deleted file mode 100644 index f09c64a54..000000000 --- a/demos/react-fast-refresh-test/src/components/new-comp.tsx +++ /dev/null @@ -1,3 +0,0 @@ -export const NewComponent = () => { - return
NEW!
; -}; -- cgit v1.2.3