diff --git a/quick-starts/react-quick-start/src/App.tsx b/quick-starts/react-quick-start/src/App.tsx index a61f29729..f32ee7f90 100644 --- a/quick-starts/react-quick-start/src/App.tsx +++ b/quick-starts/react-quick-start/src/App.tsx @@ -6,6 +6,8 @@ import { SendTransaction } from "./components/sendTransaction"; import { Balance } from "./components/getBalance"; import { SwitchChain } from "./components/switchNetwork"; // IMP END - Blockchain Calls +import { useState, useRef, useEffect } from "react"; + function App() { // IMP START - Login const { connect, isConnected, connectorName, loading: connectLoading, error: connectError } = useWeb3AuthConnect(); @@ -18,14 +20,27 @@ function App() { const { address } = useAccount(); // IMP END - Blockchain Calls + const [showConsole, setShowConsole] = useState(false); + const consoleContentRef = useRef(null); + function uiConsole(...args: any[]): void { - const el = document.querySelector("#console>p"); - if (el) { - el.innerHTML = JSON.stringify(args || {}, null, 2); + if (consoleContentRef.current) { + consoleContentRef.current.innerHTML = JSON.stringify(args || {}, null, 2); console.log(...args); } } + useEffect(() => { + if (showConsole && userInfo && consoleContentRef.current) { + uiConsole(userInfo); + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [showConsole]); + + const handleToggleConsole = () => { + setShowConsole(!showConsole); + }; + const loggedInView = (

Connected to {connectorName}

@@ -34,8 +49,8 @@ function App() { {/* // IMP END - Blockchain Calls */}
-
{/* // IMP START - Logout */} @@ -48,6 +63,11 @@ function App() {
{/* // IMP END - Logout */}
+ {showConsole && ( +
+

+
+ )} {/* IMP START - Blockchain Calls */} @@ -79,9 +99,6 @@ function App() { {isConnected ? loggedInView : unloggedInView} -
-

-