Skip to content

Commit

Permalink
fix: lint
Browse files Browse the repository at this point in the history
lint
  • Loading branch information
MadhuSaini22 committed Jan 20, 2023
1 parent 0b2019f commit f523c99
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions src/components/GoToTop.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,48 @@
import React, { useEffect, useState } from "react";
import { FaArrowUp } from "react-icons/fa";
import React, { useEffect, useState } from "react"
import { FaArrowUp } from "react-icons/fa"

const GoToTop = () => {
// state to display toggler
const [isVisible, setIsVisible] = useState(false);
const [isVisible, setIsVisible] = useState(false)

const goToBtn = () => {
window.scrollTo({ top: 0, left: 0, behavior: "smooth" });
};
window.scrollTo({ top: 0, left: 0, behavior: "smooth" })
}

const listenToScroll = () => {
const heightToHidden = 20;
const heightToHidden = 20
const winScroll =
document.body.scrollTop || document.documentElement.scrollTop;
document.body.scrollTop || document.documentElement.scrollTop

if (winScroll > heightToHidden) {
setIsVisible(true);
setIsVisible(true)
} else {
setIsVisible(false);
setIsVisible(false)
}
};
}

useEffect(() => {
window.addEventListener("scroll", listenToScroll);
return () => window.removeEventListener("scroll", listenToScroll);
}, []);
window.addEventListener("scroll", listenToScroll)
return () => window.removeEventListener("scroll", listenToScroll)
}, [])

// classes for Back to Top button
// classes for gototop button

return (
<div
onClick={goToBtn}
onKeyDown={goToBtn}
role="button"
tabIndex={0}
className={`fixed bg-gradient-to-b from-green-400 to-blue-600 animate-bounce cursor-pointer rounded-full p-3 right-12 bottom-12 ${
!isVisible ? "hidden" : ""
}`}
className={`fixed bg-gradient-to-b from-green-400 to-blue-600 animate-bounce cursor-pointer rounded-full p-3 right-12 bottom-12 ${!isVisible ? "hidden" : ""}`}
>
{isVisible && (
<div>
<FaArrowUp className="text-black" />
</div>
)}
</div>
);
};
)
}

export default GoToTop;
export default GoToTop

0 comments on commit f523c99

Please sign in to comment.