Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useEffect in Banner component #24

Closed
tynoschuck opened this issue Jan 1, 2023 · 0 comments
Closed

useEffect in Banner component #24

tynoschuck opened this issue Jan 1, 2023 · 0 comments

Comments

@tynoschuck
Copy link

Hello there!
I'm following the tutorial but I cannot make the useEffect work. Everything else in the page is working up to that point, but the dynamic text does not want to work.
Here's my code for the Banner component:
import { useState, useEffect } from "react"; import { Container, Row, Col } from "react-bootstrap"; import { ArrowRightCircle } from "react-bootstrap-icons"; import headerImg from "../assets/img/header-img.svg"; export const Banner = () => { const [loopNum, setLoopNum] = useState(0); const [isDeleting, setIsDeleting] = useState(false); const toRotate = ["Web Developer", "Web Designer", "UI/UX Designer"]; const [text, setText] = useState(""); const [delta, setDelta] = useState(300 - Math.random() * 100); const period = 2000; useEffect(() => { let ticker = setInterval(() => { tick(); }, delta); return () => { clearInterval(ticker); }; }, [text]); const tick = () => { let i = loopNum % toRotate.length; let fullText = toRotate(i); let updatedText = isDeleting ? fullText.substring(0, text.length - 1) : fullText.substring(0, text.length + 1); setText(updatedText); if (isDeleting) { setDelta((prevDelta) => prevDelta / 2); } if (!isDeleting && updatedText === fullText) { setIsDeleting(true); setDelta(period); } else if (isDeleting && updatedText === "") { setIsDeleting(false); setLoopNum(loopNum + 1); setDelta(500); } }; return ( <section className="banner" id="home"> <Container> <Row className="align-items-center"> <Col xs={12} md={6} xl={7}> <span className="tagline">Welcome to my Portfolio</span> <h1> {Hi! I'm a webdecoded} <span className="wrap">{text}</span> </h1> <p> Lorem ipsum dolor sit amet consectetur adipisicing elit. Ratione eos illo exercitationem amet iusto doloribus assumenda corrupti fuga libero quos, quasi quis. Suscipit, ipsam ullam autem soluta accusantium natus tenetur! </p> <button> Let's connect <ArrowRightCircle size={25} /> </button> </Col> <Col xs={12} md={6} xl={5}> <img src={headerImg} alt="header_img" /> </Col> </Row> </Container> </section> ); };
Screenshot from 2023-01-01 12-17-19
Thank you in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant