How to add Typewriter effect in Next.js ?
Last Updated :
05 Jan, 2023
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:
Similar Reads
How to add TypeScript in Next.js ? In this article, we will learn how to add TypeScript in Next.js.Why should we use TypeScript in our project? The fundamental concept of TypeScript is that it is type-strict, which means that each entity, be it a variable, a function, or an object has a definite data type. It allows minimum bugs in t
5 min read
How to Create Typewriter Effect in ReactJS? Learn how to enhance your React JS applications with a captivating typewriter effect using CSS and JavaScript, leveraging the typewriter-effect package for seamless and engaging UI design.ApproachTo create a typewriter effect in React, we will be using the typewriter-effect npm package. Import and u
5 min read
How to add ESLint in Next.js ? ESLint is a popular linting tool for identifying and fixing issues in JavaScript code. Adding ESLint to your Next.js project ensures that your code follows best practices and maintains a consistent style. This enhances code quality, helps catch errors early, and makes the codebase easier to maintain
3 min read
How to add CodeBlock in Next.js ? In this article, we are going to learn how we can add CodeBlock 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 conditiona
2 min read
How to Type a Page Component With Props in Next.js? Next.js is a popular React framework used for building server-side rendered and static web applications. In many situations, we likely import the components wherever necessary in the project and pass the properties or props accordingly to the component. So, in this article, we will create a componen
3 min read