Skip to content

Commit

Permalink
refactor: clean the code PE-5161
Browse files Browse the repository at this point in the history
  • Loading branch information
fedellen committed Dec 7, 2023
1 parent f54b86d commit 5110240
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { useState } from "react";
import "./App.css";
import { ArDriveLogo } from "./ArDriveLogo";
import { GiftForm } from "./GiftForm";
import { useErrorMessage } from "./hooks/useErrorMessage";

function App() {
const [errorMessage, setErrorMessage] = useState<string | undefined>(
undefined
);
const [errorMessage, setErrorMessage] = useErrorMessage();

// TODO: Router for different pages. We only need a gift form for now

Expand Down
20 changes: 20 additions & 0 deletions src/hooks/useErrorMessage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { useEffect, useState } from "react";

const errorMessageTimeout = 5_000; // 5 seconds

export function useErrorMessage(): [
string | undefined,
(message: string | undefined) => void,
] {
const [errorMessage, setErrorMessage] = useState<string | undefined>(
undefined,
);
useEffect(() => {
const timeout = setTimeout(() => {
setErrorMessage(undefined);
}, errorMessageTimeout);
return () => clearTimeout(timeout);
}, [errorMessage]);

return [errorMessage, setErrorMessage];
}

0 comments on commit 5110240

Please sign in to comment.