Build a Dictionary App Using Next Js
Last Updated :
06 Nov, 2023
In this article, we'll create a dictionary app using Next Js. The application allows users to effortlessly search for word definitions, parts of speech, and example. By utilizing an online dictionary API, the app fetches relevant word data and organizes it in a structured manner. Users can also listen to the pronunciation of words.
Preview of Final Output: Let us have a look at how the final output will look like:
Build a Dictionary App Using Next Js
Technologies Used/Prerequisites
Approach:
- The App component in this Next.js application serves as a handy tool for word lookup. It leverages React's useState to effectively manage the state. By utilizing the fetch API, the getMeaning function obtains word data from a dictionary API based on the user's input.
- Additionally, users can make use of the playAudio function to listen to correct word pronunciations. The component offers an intuitive interface that enables users to effortlessly input words and receive well-structured, comprehensive information in return.
- Furthermore, it seamlessly incorporates FontAwesome icons for search functionality and audio playback. This project not only demonstrates advanced techniques like state management, asynchronous data fetching, but also emphasizes user interaction to create a practical and efficient dictionary app.
Steps to create the NextJS Application
Step 1: Create a new Next.js project using the following command
npx create-next-app dictionary-app
Step 2: Change to the project directory:
cd dictionary-app
Project Structure:

The updated dependencies in package.json file will look like:
"dependencies": {
"next": "^13.0.6",
"react": "^18.2.0",
"react-dom": "^18.2.0"
}
Example: In this example, we will see the Dictionary App Using Next Js
- Index.js: This file implements all the logics and imports the icons
- global.css: This file contains the styling of the application.
JavaScript
import { useState } from 'react';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faSearch } from '@fortawesome/free-solid-svg-icons';
import { faVolumeUp } from '@fortawesome/free-solid-svg-icons';
export default function App() {
const [data, setData] = useState('');
const [searchWord, setSearchWord] = useState('');
async function getMeaning() {
try {
const response = await fetch(
`https://api.dictionaryapi.dev/api/v2/entries/en_US/${searchWord}`
);
const data = await response.json();
setData(data[0]);
} catch (error) {
console.error('Error fetching data:', error);
}
}
function playAudio() {
if (data.phonetics && data.phonetics[0] && data.phonetics[0].audio) {
let audio = new Audio(data.phonetics[0].audio);
audio.play();
}
}
return (
<div className="container">
<h1 className="heading">
Dictionary <span>App</span>{' '}
</h1>
<div className="searchBox">
<input
type="text"
placeholder="Search..."
onChange={(e) => {
setSearchWord(e.target.value);
}}
/>
<button
onClick={() => {
getMeaning();
}}
>
<FontAwesomeIcon icon={faSearch} size="lg" />
</button>
</div>
{data && (
<div className="showResults">
<h2>{data.word}</h2>
<button
onClick={() => {
playAudio();
}}
>
<FontAwesomeIcon icon={faVolumeUp} size="sm" />
</button>
<div className="table-container">
<table>
<tr>
<td>Parts of Speech:</td>
<td>{data.meanings[0].partOfSpeech}</td>
</tr>
<tr>
<td>Definition:</td>
<td>{data.meanings[0].definitions[0].definition}</td>
</tr>
<tr>
<td>Example:</td>
<td>{data.meanings[0].definitions[0].example}</td>
</tr>
</table>
</div>
</div>
)}
</div>
);
}
CSS
/* global.css */
body {
background-color: #f4f4f4;
}
.container {
text-align: center;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 25px 0px rgba(0, 0, 0, 0.1);
max-width: 700px;
background: white;
margin: 2rem auto;
}
.heading {
font-size: 35px;
margin-bottom: 20px;
color: #007bff;
}
.heading span {
color: #333;
}
.searchBox {
display: flex;
justify-content: center;
align-items: center;
margin-bottom: 20px;
}
input {
padding: 12px;
border: 1px solid #ccc;
border-radius: 5px;
width: 100%;
margin-right: 10px;
font-size: 16px;
color: #444;
}
button {
background-color: #007bff;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
padding: 12px 20px;
font-size: 16px;
}
button:hover {
background-color: #0056b3;
}
.showResults {
text-align: left;
border: 3px solid #ccc;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
background-color: #fff;
text-transform: capitalize;
}
h2 {
font-size: 24px;
margin-bottom: 10px;
color: #333;
}
table {
width: 100%;
}
tr {
line-height: 1.6;
border-bottom: 1px solid #ccc;
padding: 10px 0;
}
td:first-child {
font-weight: bold;
width: 30%;
color: #007bff;
}
.table-container {
margin-top: 20px;
}
Steps to run the application:
Step 1: Run this command to start the application:
npm run dev
Step 2: To run the next.js application use the following command and then go to this URL:
http://localhost:3000
Output:

Similar Reads
Blogging Platform using Next JS In this project, we will explore the process of building The Blogging Platform with Next.js. Blogging Platform is a web application that allows users to create and publish blog posts. The platform provides a user-friendly interface for managing blog content and includes functionalities to create new
5 min read
How to Create Todo App using Next.js ? In this article, we will create a to-do application and understand the basics of Next.js. This to-do list can add new tasks we can also delete the tasks by clicking on them.Next.js is a widely recognized React framework that eÂnables server-side rendering and enhanceÂs the developmeÂnt of interacti
4 min read
Document Management System using NextJS The Document Management System is a web application developed using Next.js, that allows users to efficiently manage their documents. The system provides features for uploading, organizing, and retrieving documents. Users can upload documents through the web interface, which are then stored in local
5 min read
Create a Quiz App with Next JS In this article, weâll explore the process of building a Quiz App utilizing NextJS. The quiz app provides users with a series of multiple-choice questions with options. Users can select the option and move to the next question. At the end, the user will be able to see the analysis of the quiz.Output
5 min read
E-commerce Dashboard with NextJS This project is an E-commerce Dashboard built with Next.js, providing features such as a dynamic sidebar, responsive navigation, order analytics, and most sold items of the week. It shows various features such as product analytics, order management, and user interaction. Output Preview: Prerequisite
11 min read
Social Networking Platform using Next.js The Social Networking Platform built with NextJS is a web application that provides users the functionality to add a post, like a post, and be able to comment on it. The power of NextJS, a popular React framework for building server-side rendered (SSR) and statically generated web applications, this
8 min read
URL Shortener Service with NextJS In this article, we will explore the process of building a URL shortener service using NextJS that takes a long URL and generates a shorter, more condensed version that redirects to the original URL when accessed. This shortened URL is typically much shorter and easier to share, especially in situat
2 min read
Contact Us Form using Next.js Creating a Contact Us form in Next.js involves setting up a form component, handling form submissions, and potentially integrating with a backend service or API to send the form data. In this article, we will create a Contact Us Form with NextJS.Output Preview: Letâs have a look at what our final pr
6 min read
Blogging Platform using Next JS In this project, we will explore the process of building The Blogging Platform with Next.js. Blogging Platform is a web application that allows users to create and publish blog posts. The platform provides a user-friendly interface for managing blog content and includes functionalities to create new
5 min read
Music Player App with Next.js and API In this tutorial, we'll create a Music Player App using NextJS, a React framework. Explore frontend development, API integration, and UI design to build a user-friendly app for seamless music enjoyment. Join us in harmonizing code and creativity to craft an engaging Music Player App with NextJS in t
3 min read