This is a solution to the Dictionary Web App challenge on Frontend Mentor. Frontend Mentor challenges help you improve your coding skills by building realistic projects.
Users should be able to:
async function fetchDefinition(word: string) {
const res = await fetch(
`https://api.dictionaryapi.dev/api/v2/entries/en/${word}`
);
if (!res.ok) {
throw new Error("Failed to fetch data");
}
const data = await res.json();
const searchedWord: Word = data[0];
return searchedWord;
}
export default fetchDefinition;
const data = await fetchDefinition(word);
if (!data) {
notFound();
}
export default function NotFound() {
return (
<div className="flex flex-col items-center space-y-10 mt-32 text-center">
<h2 className="font-bold text-4xl uppercase">
Sorry I Could't Find a Definition
</h2>
<p className="text-2xl">Please try search for another word or phrase.</p>
</div>
);
}