Saturday, December 28, 2024
Google search engine
HomeLanguagesHow to create typewriter effect in ReactJS ?

How to create typewriter effect in ReactJS ?

The typewriter effect, where text appears as if it’s being typed out letter by letter, can add an engaging and dynamic element to your React.js applications. It creates a visually appealing animation that grabs the user’s attention. In this article, we will explore how to implement a typewriter effect in React.js using CSS and JavaScript.

The typewriter effect in ReactJS is a JS package that can be used for a better UI design. This effect allows us to create a simple typing animation in ReactJS. For using Typewriter in ReactJS we need to install the typewriter-effect package.

Prerequisites:

  • Basics of ReactJS
  • Already created ReactJSapp

Below all the steps are described order-wise to use styled-components in React.

Installation:

  • Step 1: Before moving further, firstly we have to install the typewriter-effect, by running the following command in your project directory, with the help of terminal in your src folder or you can also run this command in Visual Studio Code’s terminal in your project folder.
npm install --save typewriter-effect
yarn add typewriter-effect
  • Step 2: After installing the package, now open your App.js file which is present inside your project’s directory, under the src folder, and delete the code present inside it.
  • Step 3: Now import React and typewriter-effect package.
  • Step 4: In your app.js file, add this code snippet to import React and typewriter-effect package.
import React from 'react';
import Typewriter from "typewriter-effect";

Below is a sample program to illustrate the use of the typewriter-effect :

Filename- App.js:

Javascript




import React from 'react';
 
//importing typewriter-effect
import Typewriter from "typewriter-effect";
import './App.css';
 
function App() {
    return (
        <div className="App">
            <Typewriter
 
                onInit={(typewriter) => {
                    typewriter
                        .typeString("GeeksForGeeks")
                        .pauseFor(1000)
                        .deleteAll()
                        .typeString("Welcomes You")
                        .start();
                }}
            />
        </div>
    );
}
 
export default App;


Filename- App.css

CSS




.App {
    font-family: sans-serif;
    font-weight: 800;
    font-size: 40px;
    text-align: center;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: green;
}


Output: Hence using the above-mentioned steps, we can use the typewriter-effect to import and change the typing animation React

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments