|
|
@ -1,33 +1,42 @@ |
|
|
|
import { useState, useEffect } from 'react'; |
|
|
|
import { useState, useEffect, useCallback} from 'react'; |
|
|
|
import { Col, Container, Row } from 'react-bootstrap'; |
|
|
|
import { ArrowRightCircle } from 'react-bootstrap-icons'; |
|
|
|
import HeadImg from '../assets/img/header-img.svg'; |
|
|
|
|
|
|
|
const Banner = () => { |
|
|
|
const job = "Web Developer"; |
|
|
|
const [text, setText] = useState(''); |
|
|
|
const [delta, setDelta] = useState(300); // Set an initial value
|
|
|
|
const period = 2000; |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
let ticker = setInterval(() => { |
|
|
|
tick(); |
|
|
|
}, delta); |
|
|
|
return () => { clearInterval(ticker); }; |
|
|
|
}, [text]); |
|
|
|
|
|
|
|
const tick = () => { |
|
|
|
const fullText = job; |
|
|
|
const updatedText = fullText.substring(0, text.length +1); |
|
|
|
setText(updatedText); |
|
|
|
|
|
|
|
if(updatedText === fullText) { |
|
|
|
setTimeout(() => { |
|
|
|
setText(''); |
|
|
|
setDelta(300); |
|
|
|
}, period) |
|
|
|
} |
|
|
|
}; |
|
|
|
const job = "Web Developer"; |
|
|
|
const [text, setText] = useState(''); |
|
|
|
const [isDeleting, setIsDeleting] = useState(false); // Track whether we are deleting
|
|
|
|
const [delta, setDelta] = useState(300); // Set an initial value
|
|
|
|
const period = 2000; |
|
|
|
|
|
|
|
const tick = useCallback(() => { |
|
|
|
const fullText = job; |
|
|
|
let updatedText = ''; |
|
|
|
|
|
|
|
if (isDeleting) { |
|
|
|
updatedText = fullText.substring(0, text.length - 1); |
|
|
|
} else { |
|
|
|
updatedText = fullText.substring(0, text.length + 1); |
|
|
|
} |
|
|
|
|
|
|
|
setText(updatedText); |
|
|
|
|
|
|
|
if (!isDeleting && updatedText === fullText) { |
|
|
|
setTimeout(() => setIsDeleting(true), period); |
|
|
|
} else if (isDeleting && updatedText === '') { |
|
|
|
setIsDeleting(false); |
|
|
|
} |
|
|
|
|
|
|
|
setDelta(isDeleting ? 150 : 300); // Adjust speed for deleting and typing
|
|
|
|
}, [isDeleting, text, job, period]); |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
let ticker = setInterval(() => { |
|
|
|
tick(); |
|
|
|
}, delta); |
|
|
|
return () => { clearInterval(ticker); }; |
|
|
|
}, [tick, delta]); // Include tick and delta in the dependency array
|
|
|
|
|
|
|
|
return ( |
|
|
|
<section className='banner' id="home"> |
|
|
|