Вы можете попробовать что-то вроде этого Машинопись:
import React, {useState, useEffect} from "react";
export const AnimatedInput = ({placeholder: passedPlaceholder = "", ...passedProps}: React.InputHTMLAttributes<HTMLInputElement>) => {
const [placeholder, setPlaceholder] = useState(passedPlaceholder.slice(0, 0));
const [placeholderIndex, setPlaceholderIndex] = useState(0);
useEffect(() => {
const intr = setInterval(() => {
setPlaceholder(passedPlaceholder.slice(0, placeholderIndex));
if (placeholderIndex + 1 > passedPlaceholder.length) {
setPlaceholderIndex(0)
} else {
setPlaceholderIndex(placeholderIndex + 1)
}
}, 150);
return () => {
clearInterval(intr)
}
},);
return <input {...passedProps} placeholder={placeholder}/>
};
Javascript:
import React, {useState, useEffect} from "react";
export const AnimatedInput = ({placeholder: passedPlaceholder = "", ...passedProps}) => {
const [placeholder, setPlaceholder] = useState(passedPlaceholder.slice(0, 0));
const [placeholderIndex, setPlaceholderIndex] = useState(0);
useEffect(() => {
const intr = setInterval(() => {
setPlaceholder(passedPlaceholder.slice(0, placeholderIndex));
if (placeholderIndex + 1 > passedPlaceholder.length) {
setPlaceholderIndex(0)
} else {
setPlaceholderIndex(placeholderIndex + 1)
}
}, 150);
return () => {
clearInterval(intr)
}
},);
return <input {...passedProps} placeholder={placeholder}/>
};
Использование:
<AnimatedInput placeholder="type a name"/>