Open In App

How to create a Dictionary App in ReactJS ?

Last Updated : 05 Aug, 2021
Like Article

In this article, we will be building a very simple Dictionary app with the help of an API. This is a perfect project for beginners as it will teach you how to fetch information from an API and display it and some basics of how React actually works. Also, we will learn about how to use React icons. Let’s begin.

Approach: Our app contains two sections, one for taking the user input and the other is for displaying the data. Whenever a user searches for a word, we store that input in a state and trigger an API call based on the searched keyword parameter. After that when the API call is made, we simply store that API response in another state variable, and then we finally display the information accordingly.

Prerequisites: The pre-requisites for this project are:

Creating a React application and installing some npm packages:

Step 1: Create a react application by typing the following command in the terminal:

npx create-react-app dictionary-app

Step 2: Now, go to the project folder i.e dictionary-app by running the following command:

cd dictionary-app

Step 3: Let’s install some npm packages required for this project:

npm install axios
npm install react-icons --save

Project Structure: It should look like this:

Example: It is the only component of our app that contains all the logic. We will be using a free opensource API (no auth required) called ‘Free Dictionary API’ to fetch all the required data. Our app contains two sections i.e a section for taking the user input and a search button, the other is for displaying the data. Apart from displaying the information that we received, we will also have a speaker button that lets users listen to the phonetics.

Now write down the following code in the App.js file. Here, the App is our default component where we have written our code. Here, the filename is App.js and App.css


import { React, useState } from "react";
import Axios from "axios";
import "./App.css";
import { FaSearch } from "react-icons/fa";
import { FcSpeaker } from "react-icons/fc";
function App() {
  // Setting up the initial states using react hook 'useState'
  const [data, setData] = useState("");
  const [searchWord, setSearchWord] = useState("");
  // Function to fetch information on button
  // click, and set the data accordingly
  function getMeaning() {
    ).then((response) => {
  // Function to play and listen the
  // phonetics of the searched word
  function playAudio() {
    let audio = new Audio(data.phonetics[0].audio);;
  return (
    <div className="App">
      <h1>Free Dictionary</h1>
      <div className="searchBox">
        // Taking user input
          onChange={(e) => {
          onClick={() => {
          <FaSearch size="20px" />
      {data && (
        <div className="showResults">
            {data.word}{" "}
              onClick={() => {
              <FcSpeaker size="26px" />
          <h4>Parts of speech:</h4>
export default App;


@import url(
@import url(
.App {
  height: 100vh;
  width: 100vw;
  display: flex;
  flex-direction: column;
  align-items: center;
  background-color: #f6f6f6;
  background-image: linear-gradient(315deg, #f6f6f6 0%, #e9e9e9 74%);
  font-family:'Poppins', sans-serif;
h1 {
  text-align: center;
  font-size: 3em;
  font-family: 'Pacifico', cursive;
  color: #4DB33D;
  padding: 1.5em;
  font-size: 30px;
  text-decoration: underline;
  padding-bottom: 20px;
  color: #4DB33D;
  width: 400px;
  height: 38px;
  font-size: 20px;
  padding-left: 10px;
.searchBox > button{
  background-color: #4DB33D;
  height: 38px;
  width: 60px;
  border: none;
  color: white;
  box-shadow: 0px 3px 2px #439e34;
  cursor: pointer;
  padding: 0;
  width: 500px;
  padding: 20px;
.showResults > h2 > button{
  background: none;
  border: none;
  cursor: pointer;

Step to Run Application: Run the application using the following command from the root directory of the project:

npm start

Output: Now open your browser and go to http://localhost:3000/, you will see the following output:


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads