Search

Back

Copy Link

Library

/

Free

/

52

Typing Effect

52

Typing Effect

Not loading? Preview

Made by

@frameroverrides

override

none

Override

Typing Effect

Copy

Override

Copied to Clipboard!

Instructions

Apply to any text layer. Edit the phrases however you’d like and add or remove some.

Code Preview

import type { ComponentType } from "react"
import { useEffect, useState } from "react"

const words = [
        "Hi my name is Danny",
        "I'm a senior product designer",
        "I write about design",
        "I'm an entrepreneur",
        "I'm a scuba diver and travel enthusiast",
    ],
    skip_delay = 15,
    speed = 70

export function withTypingEffect(Component): ComponentType {
    return (props) => {
        const [part, setPart] = useState("")
        const [i, setI] = useState(0)
        const [offset, setOffset] = useState(0)
        const [forwards, setForwards] = useState(true)
        const [skipCount, setSkipCount] = useState(0)

        useEffect(() => {
            const interval = setInterval(() => {
                if (forwards) {
                    if (offset >= words[i].length) {
                        setSkipCount((skipCount) => skipCount + 1)
                        if (skipCount === skip_delay) {
                            setForwards(false)
                            setSkipCount(0)
                        }
                    }
                } else {
                    if (offset === 0) {
                        setForwards(true)
                        setI((i) => {
                            const nextI = i + 1
                            return nextI >= words.length ? 0 : nextI
                        })
                        setOffset(0)
                    }
                }
                setPart(words[i].substr(0, offset))
                if (skipCount === 0) {
                    setOffset((offset) => (forwards ? offset + 1 : offset - 1))
                }
            }, speed)
            return () => clearInterval(interval)
        }, [i, offset, forwards, skipCount])

        return <Component {...props} text={part} />
    }
}

Terms of Use for Free Assets

By accessing and using this Framer Override Library, you agree to the following terms:

All code snippets provided are available for your personal and professional use. This includes personal websites, client projects, and other website projects in Framer. You are strictly prohibited from sharing, redistributing, selling these code snippets, or creating derivative works for resale or distribution. Unauthorized sharing, distribution, or selling of these code snippets is a breach of these terms and may result in termination of your access to this library, along with potential legal action.