Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

How to add Typewriter effect in Next.js ?

  • Last Updated : 22 Nov, 2021

In this article, we are going to learn how we can add the Typewriter effect in NextJs. NextJS is a React-based framework. It has the power to Develop beautiful Web applications for different platforms like Windows, Linux, and mac. The linking of dynamic paths helps in rendering your NextJS components conditionally.

Approach: To add our typewriter effect we are going to use the typewriter-effect package. The typewriter-effect package helps us to add the typewriter effect anywhere in our app. So first, we will install the typewriter-effect package and then we will add the effect on our homepage.

Create NextJS Application: You can create a new NextJs project using the below command:

npx create-next-app gfg

Install the required package: Now we will install the typewriter-effect package using the below command:

npm i typewriter-effect

Project Structure: It will look like this.

Adding the Effect: We can easily add the typewriter effect in our app after installing the typewriter-effect package. For this example, we are going to add the effect to our homepage.

Add the below content in the index.js file:

Javascript




import React from "react";
import Typewriter from 'typewriter-effect';
  
export default function TypingEffect() {
  return (
    <div>
      <h3>GeeksforGeeks Typing Animation</h3>
      <Typewriter
        onInit={(typewriter) => {
          typewriter.typeString('Hello World!')
            .callFunction(() => {
              console.log('String typed out!');
            })
            .pauseFor(2500)
            .deleteAll()
            .callFunction(() => {
              console.log('All strings were deleted');
            })
            .start();
        }}
      />
    </div>
  );
}


Explanation: In the above example first, we are importing the Typewriter component from the installed package. After that, we are adding the pause timing, deleteAll function, and the text in which we want to add text in our Typewriter component.

Steps to run the application: Run the below command in the terminal to run the app.

npm run dev

Output:

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!