This project is an implementation of a typewriter effect using React and TypeScript.
To use the <TypeWriter> component, you need pass it the following props:
| Name | Type | Default | Description |
|---|---|---|---|
| elementType | string |
required |
Is the element to render (if you want a more types of elements only edit its interface ). |
| text | string |
required |
A string to apply the effect.. |
| interval | number (optional) |
20 |
The interval between character writed |
| classNames | string (optional) |
"" |
ClassName to add to the Element created |
| delay | number (optional) |
0 |
A number indicating the delay in milliseconds to start to write |
Example:
import { TypeWriter } from './components/TypeWriter'
export const Example = () => {
return (
<TypeWriter
elementType='p'
text={`Hello world, \n\n This is a test`}
/>
)
}To use the <TypeWriterInView> component, the principal diference between the normal is that it uses the library react-intersection-observer for show the element when is in the viewport . You need pass it the following props:
| Name | Type | Default | Description |
|---|---|---|---|
| elementType | string |
required |
Is the element to render (if you want a more types of elements only edit its interface ). |
| text | string |
required |
A string to apply the effect.. |
| interval | number (optional) |
20 |
The interval between character writed |
| classNames | string (optional) |
"" |
ClassName to add to the Element created |
| delay | number (optional) |
0 |
A number indicating the delay in milliseconds to start to write |
Example:
import { TypeWriterInView } from './components/TypeWriterInView'
export const Example = () => {
return (
<TypeWriterInView
elementType='p'
text={`Hello world, \n\n This is a test`}
/>
)
}if you want use TypeWriterInView into array I recommend remove this part and create another component and recive the porp InView.
const [ref, inView,node] = useInView({
rootMargin: '-100px 0px',
triggerOnce: true
})- React - A JavaScript library for building user interfaces
- TypeScript - A superset of JavaScript that adds optional static typing
- Vite - A development server that allows for instant development and hot-module replacement
- react-intersection-observer - A React component for the Intersection Observer API
yarn dev: Runs the development server with hot-module replacementyarn build: Compiles the project with TypeScript and creates a production-ready build in the dist folderyarn preview: Runs the development server and opens the app in the browseryarn test: Runs the test suiteyarn test:watch: Runs the test suite in watch mode
@types/jest: TypeScript definitions for Jest@types/react: TypeScript definitions for React@types/react-dom: TypeScript definitions for React-DOM@types/react-test-renderer: TypeScript definitions for React-Test-Renderer@vitejs/plugin-react: A Vite plugin for Reactjest: A JavaScript testing frameworkjest-environment-jsdom: Jest environment using JSDOMreact-test-renderer: A package for testing React componentsts-jest: A TypeScript preprocessor for Jesttypescript: A superset of JavaScript that adds optional static typingvite: A fast and productive front-end development build tool
Environment:
node v16.17.0
yarn 1.22.19
npm 8.15.0
To run this project locally, clone the repository and install the dependencies:
git clone <repo-link>
cd typewriter-effect
yarn installThen, start the development server:
yarn dev
