Create Application Structure of Character Counter

In this step, we will create the basic structure to the application such as container, text input areas and display area. This will make it easy to view the elements we need for the application.

  • For the character counter, we need one text area to get the dynamic input from the user and one display area to display the results.
  • As the first stage, create a components folder in the src directory and create a file with the name CharacterCounter.jsx

  • Now, copy and paste the code to create the basic structure of the application.
// character counter.jsx 



// Functional Component to Create the character counter 



function CharacterCounter() {

    return (

   // The main container 

    <div>

// The input container 

      <div>

        // The text area

        <textarea

          id="input"

          placeholder="Enter a text"

          value={text}

         />

      </div>

      // The result container

      <div>

       // The Character count section

        <div>

          <span id="characterCount">0</span>

          <span>Characters</span>

        </div>

        // The word count section

        <div>

          <span id="wordCount">0</span>

          <span>Words</span>

        </div>

      </div>

    </div>

  );

}



export default CharacterCounter;
  • After the character counter component export, you need to import the component in the main component App.jsx since it is the entry point for your application.
  • Modify the code in App.jsx file similar to the below code.
// App.jsx 



// Import the character counter component 

import CharacterCounter from "./components/CharacterCounter";



function App() {

  return (

    // The main container

    <div>

      // The header container

      <div>

  // The application title

        <h1>Character Counter App</h1>

      </div>

// The Character counter component

      <CharacterCounter />

    </div>

  );

}



export default App;
  • After updating the App component, you will see the following result.