React
Word Game
Game Development
JavaScript
Web Development
Programming
Coding Tutorial

How to Build a Word Game in React: A Step-by-Step Guide

Listen to article
Deepak Tewatia
September 7, 2025
4 min read

Introduction

Want to create a fun word game using React? In this guide, we will walk you through each step. You’ll learn how to set up your project, build the game board, add words, and make it interactive. By the end, you’ll have a cool game to share with your friends! Let's get started!

Setting Up Your Project

The first step is to set up your React project. You can use Create React App to do this easily. Open your terminal and run the following command:

npx create-react-app word-game

This command creates a new folder called "word-game" with all the files you need to start. Once it's done, navigate into the new folder:

cd word-game

Now, you can open this folder in your favorite code editor. You’ll see the default files that come with Create React App.

Building the Game Board

Next, let’s build the game board. Open the src/App.js file. This is where most of your code will go. First, we’ll set up the basic structure of our game board.

Replace the default content in App.js with this code:

import React, { useState } from 'react';
import './App.css';

function App() {
  const [words, setWords] = useState([]);
  const [inputValue, setInputValue] = useState('');

  const addWord = () => {
    if (inputValue.trim() !== '') {
      setWords([...words, inputValue]);
      setInputValue('');
    }
  };

  return (
    <div className="App">
      <h2>Word Game</h2>
      <input
        type="text"
        value={inputValue}
        onChange={(e) => setInputValue(e.target.value)}
        placeholder="Enter a word"
      />
      <button onClick={addWord}>Add Word</button>
      <ul>
        {words.map((word, index) => (
          <li key={index}>{word}</li>
        ))}
      </ul>
    </div>
  );
}

export default App;

Here's what this code does:

  • It imports React and the necessary hooks.
  • It uses useState to keep track of the words and the input value.
  • It has an addWord function that adds a word to the list when you click the button.
  • It displays a list of words you enter.

Making It Interactive

Now that we have a basic board, let’s make it more interactive. We can add a feature to check if a word exists in a predefined list. First, create a list of predefined words in App.js:

const predefinedWords = ['apple', 'banana', 'cherry', 'date', 'fig', 'grape'];

Next, modify the addWord function to check if the entered word exists in the list. Update the function like this:

const addWord = () => {
  if (inputValue.trim() !== '') {
    if (predefinedWords.includes(inputValue.toLowerCase())) {
      setWords([...words, inputValue]);
      setInputValue('');
    } else {
      alert('Word not found!');
    }
  }
};

What this really means is now, when you enter a word, it checks if that word is in our list. If it is, it adds it. If not, an alert tells you that the word is not found.

Styling Your Game

Now that your game works, let’s make it look better. Open src/App.css and add some basic styles:

body {
  font-family: Arial, sans-serif;
  background-color: #f4f4f4;
  margin: 0;
  padding: 20px;
}

.App {
  max-width: 600px;
  margin: auto;
  background: white;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 0 10px rgba(0,0,0,0.1);
}

input {
  padding: 10px;
  width: calc(100% - 22px);
  margin-bottom: 10px;
}

button {
  padding: 10px 20px;
  cursor: pointer;
}

ul {
  list-style-type: none;
  padding: 0;
}

This will give your game a clean look and make it enjoyable to play.

Testing Your Game

To see your game in action, go back to your terminal and start the development server with:

npm start

Your browser should open up, and you can start entering words. Make sure to try both words in and not in your list to see how it behaves.

Conclusion

You’ve now built a simple word game using React! You set up your project, created a game board, added functionality, and styled your game. This is just the beginning. You can add more features, like scoring, timers, or even multiplayer options. The possibilities are endless!

Feel free to share your game with friends or even expand on it. Happy coding!

Comments

Y
You
Commenting
0/2000
Loading comments…