Skip to content

Commit 078d894

Browse files
committed
refactor: inline Main component
resolves re-render issue until global state
1 parent 26f4c0c commit 078d894

File tree

1 file changed

+62
-64
lines changed

1 file changed

+62
-64
lines changed

src/App.tsx

Lines changed: 62 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -211,69 +211,6 @@ function App() {
211211
return child.pid;
212212
}
213213

214-
const Main = () => (
215-
<main className="flex flex-col flex-grow items-center justify-center gap-5">
216-
<h1 className="text-3xl font-extrabold">Zero Knowledge Network</h1>
217-
218-
<img
219-
src="/zkn.svg"
220-
alt="ZKN"
221-
onClick={() => isConnected && disconnect()}
222-
className={`logo ${isConnected ? "pulsing" : ""}`}
223-
/>
224-
225-
{platformSupported &&
226-
(clientPid === 0 ? (
227-
<>
228-
<p>Enter a network identifier for access.</p>
229-
<form
230-
className="join"
231-
onSubmit={(e) => {
232-
e.preventDefault();
233-
connect();
234-
235-
// blur the input field to clear visual artifact
236-
e.currentTarget.querySelector("input")?.blur();
237-
}}
238-
>
239-
<input
240-
className="input validator focus:outline-none join-item"
241-
onChange={(e) => setNetworkId(e.currentTarget.value)}
242-
placeholder="Enter a network id..."
243-
maxLength={36}
244-
minLength={5}
245-
required
246-
list="networks"
247-
/>
248-
<datalist id="networks">
249-
{networks.map((n) => (
250-
<option key={n} value={n} />
251-
))}
252-
</datalist>
253-
<button className="btn btn-primary join-item" type="submit">
254-
Connect
255-
</button>
256-
</form>
257-
</>
258-
) : (
259-
<>
260-
<p className="text-lg font-bold">Connected Network: {networkId}</p>
261-
<button onClick={disconnect} className="btn btn-secondary">
262-
Disconnect
263-
</button>
264-
</>
265-
))}
266-
267-
{msg && (
268-
<p
269-
className={`alert ${msgType === "error" ? "alert-error" : "alert-info"}`}
270-
>
271-
{msg}
272-
</p>
273-
)}
274-
</main>
275-
);
276-
277214
const Footer = () => (
278215
<footer className="footer footer-center bg-base-200 text-base-content/30 p-4">
279216
<div className="flex flex-row">
@@ -288,7 +225,68 @@ function App() {
288225

289226
return (
290227
<div className="flex flex-col min-h-screen">
291-
<Main />
228+
<main className="flex flex-col flex-grow items-center justify-center gap-5">
229+
<h1 className="text-3xl font-extrabold">Zero Knowledge Network</h1>
230+
231+
<img
232+
src="/zkn.svg"
233+
alt="ZKN"
234+
onClick={() => isConnected && disconnect()}
235+
className={`logo ${isConnected ? "pulsing" : ""}`}
236+
/>
237+
238+
{platformSupported &&
239+
(clientPid === 0 ? (
240+
<>
241+
<p>Enter a network identifier for access.</p>
242+
<form
243+
className="join"
244+
onSubmit={(e) => {
245+
e.preventDefault();
246+
connect();
247+
248+
// blur the input field to clear visual artifact
249+
e.currentTarget.querySelector("input")?.blur();
250+
}}
251+
>
252+
<input
253+
className="input validator focus:outline-none join-item"
254+
onChange={(e) => setNetworkId(e.currentTarget.value)}
255+
placeholder="Enter a network id..."
256+
maxLength={36}
257+
minLength={5}
258+
required
259+
list="networks"
260+
/>
261+
<datalist id="networks">
262+
{networks.map((n) => (
263+
<option key={n} value={n} />
264+
))}
265+
</datalist>
266+
<button className="btn btn-primary join-item" type="submit">
267+
Connect
268+
</button>
269+
</form>
270+
</>
271+
) : (
272+
<>
273+
<p className="text-lg font-bold">
274+
Connected Network: {networkId}
275+
</p>
276+
<button onClick={disconnect} className="btn btn-secondary">
277+
Disconnect
278+
</button>
279+
</>
280+
))}
281+
282+
{msg && (
283+
<p
284+
className={`alert ${msgType === "error" ? "alert-error" : "alert-info"}`}
285+
>
286+
{msg}
287+
</p>
288+
)}
289+
</main>
292290
<Footer />
293291
</div>
294292
);

0 commit comments

Comments
 (0)