how to make page scroll to the top jsx

componentDidMount() {
  window.scrollTo(0, 0)
}

3.5
3

                                    //__view.jsx
const ScrollTopView = (props) => {
	const { onScroll, onVisbile, visible } = props

	console.log(visible)
	if (typeof window === 'object') window.addEventListener('scroll', onVisbile)

	return (
		<>
			<div
				style={{
					position: 'fixed',
					bottom: 30,
					right: 30
				}}>
				<button
					className='btn btn-primary btn-small'
					onClick={onScroll}
					style={{ display: visible ? 'inline-block' : 'none', borderRadius: 5 }}>
					ScrollTop
				</button>
			</div>
			<h1 style={{ position: 'fixed', bottom: 25, left: '40%', display: visible ? 'inline-block' : 'none' }}>End Scroll</h1>
		</>
	)
}

export default ScrollTopView

// index.jsx
import ScrollTopView from './__view'
import { createElement, useState } from 'react'

const ScrollTop = () => {
	const [visible, setVisible] = useState(false)

	const onVisbile = () => {
		const scrolled = document.documentElement.scrollTop
		if (scrolled >= 600) setVisible(true)
		else if (scrolled <= 300) setVisible(false)
	}

	const onScroll = () => {
		if (typeof window === 'object') window.scrollTo({ top: 0, behavior: 'smooth' })
	}

	return createElement(ScrollTopView, {
		onScroll,
		onVisbile,
		visible
	})
}

export default ScrollTop

3.5 (4 Votes)
0
3.89
9
Pacomme 115 points

                                    componentDidMount() {
  window.scrollTo(0, 0)
}

3.89 (9 Votes)
0
3.67
3
M Wells 90 points

                                    useEffect(() => {
  window.scrollTo(0, 0)
}, [])

3.67 (3 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
scroll into view goes to top react scroll to top react español window scroll top react how to create scroll to top button in reactjs example code react how to scroll to top react scroll scroll to top detect scroll to top a div react how to scroll to top react how to auto scroll to the top of the page using react react js on click scroll to top react scroll functional component to top react scroll window to top windows scroll top reactjs scroll to top from current position react scroll page to top js react on mount react js scroll to top of a div scoll to top react react js scroll to top of element scroll to top react button scroll to top new page react scroll to top react onchnage scroll to the top react page react scroll to top of com window scrollto top react scroll web page to top react scrollTo top in react react add scroll to top how to scroll to top of the page in react scroll to top react rouetr scroll item to top react scroll to top of page react functional component react ref scroll to top make component scroll to top when load reactjs scroll to top page react on render in react.js react-use scroll to top bottom to top scroll in reactjs scroll Top with option react scroll to top of page in react how to scroll top top when page loads in react how to scroll an element to top in react react js scroll to top all pages how to move scroll to top in reactjs scroll to top in functional component react js scroll to top of page on visiting a page in react scroll to the top of the page javascript react react scroll ref to top how to scroll to top of screen in react js stick on scroll to top REACT js how to scroll to the top using a button in react react auto scroll ot top react scroll to top auto how to create scroll to top button in react scroll always on top in react react on page load scroll to top scroll to the top of the page after render in react.js scroll position to top react scroll top scroll left react js particular div scroll to top in react how to set your scroll position to top of your page in react js react scroll to top of component not page react div scroll to top get scroll top react react scroll to top with react-scroll scroll to top reacttjs scroll to top button reactjs scroll to top in react in new page react auto scroll to top react window scroll top to element react scroll top to element react new page scroll to top window scroll to top react react scroll to top react scroll to top function react scroll to top div react scroll top top react reacct scroll to top scroll top component react react scroll to top of the page scroll to top of a div in react scroll to top of an element in react react js scroll to top when clicked react scroll to top of component with id react set scroll top on render how to scroll to top in react js react always scroll to top scroll to top on react router react router dom scroll to top scroll to the top every render in react.js scroll to the top react js does not scroll scroll to the top react js can not scroll to top react make scroll bar to the top every render react js how to make scroll in the top react react window scroll to the top javascript react scroll screen to top react make div scroll to top react scroll to top component react scroll component to top scroll to top using react js button scroll to top react react scroll to top on button sccoll to top react react scroll to top of screen how to add scroll to top with react component scroll page to top react hwo to scroll to top in react how to make scroll to top react component react scroll to top of div scroll to top in reactjs react functional component scroll to top scroll to top button in react js scroll on top react how to go scroll top react react top to scroll scroll page to top javascript reacjs how to move scrollbar to top using reactjs reactjs how to move the scroll bar to top auto scroll to top react restor scroll position to top react scroll to the top button react js routing in react js scroll to top scroll div into top react react on first render scroll top scroll to react goes past top of element get scroll position to top react js react window scroll to top scroll to top event react how to add scroll to top in react move scrollbar to top react scroll to top on alla pages react scroll to top of page react javascript react page open scroll to top scroll to top button react set scroller at top in reactjs set scroller on top in reactjs how to scroll to the top page in react react scroll top button react scroll on top scroll top button react react-scroll scroll to top react scroll to top hooc react scroll abck tot top scroll to top on link react react scroll back to top react scroll top when component load react check scroll to top react scrolled to top reactjs scroll to top of page react scroll top top react link scroll to top scroll to top of element react react programmatically scroll to the top show on top with scroll content in reactjs link in react scroll to top react function scroll to top react-scroll link to top scroll to top raect scroll element to the top in react scroll div to top react how to add scroll to top in class component in reactjs react scroll to top on render how to scroll to the top in react react scroll to top button react js scroll to top button react form wizard scroll top on page change how to move scroll at top in react scrolling to the top of a react element react scroll top of element react scrollto top scroll to top on a table react react go to top of screen how to reach top of the page after react navigation force the scrolltotop position in react hooks onload scroll to top position in react.js go top of page react react scroll to element elegantly scrool the page on start to center react when page sence the scroll its move to the next anchor react js react js scroll to top phone scroll should move to top in react on every page react add scrollport react-scroll to top on button click move to top when clicking next in panel react js react scroll arrow another page scroll topreact force scroll window to top on component mount react force sroll window to top on componenet mount scroll to top javascript react croll to top react to the top button react example how to scroll top top of div in reactjs react default at top of page return to top button react useRef force page to be at top react scroll to top reactnative hooks scroll to top of section in reactjs scrollto top with react hooks sroll to top functional componente react react scroll up to top button react scroll to top of element reactjs button to send to top of page useEffect(() => { fetch('/home') .then(window.scrollTo(0, 0)) }) automatically comes to top while refrehed in react js reactjs back to top smooth react setting scrolltop javascript scrolltop of component react on click scroll to top scroll top set using state on div react after click on top of page react js react scroll to top of page on click scroll on button click react hooks scroll to top on button click react how to make sure page is scrolled to the top when render react react force scroll to top how to set scroll bar at top on page load react scroll div top on button click in reactjs react how to scroll top of page react how to drag top of page react router scroll to top react page not starting from top scrollto top react window scroll top 0 in reactjs window scroll top in reactjs scroll to top react brokes scroll to top react blokes after i click on certain page how to scroll top in react js react button renders on top react when click on <link> content loaded first befre scroll react js on scroll top how to make page start at the top of screen on react how to bring user to the top of the screen in reactjs when scrolling scroll onle one part in page app react jsx react page doesn scroll to top scroll to top on load react react scroll to top after component change component rendering scrolled react automatic scroll to top every component react scrolltop example how to set scroll.scrollToTop with id in react js how to use scrollToTop in partiacl page in react js react scroll to top when site loaded component did mount scroll to top when site is loaded component did mount scroll to top react component did mount scroll to top scroll to top on new page react react go back to top add go to top icon react scroll to top component react react when click on link scroll to top react always set scroll to top react scroll to top page componentdidmount scroll to element componentdidmount scroll to top react scroll to bottom jump top react js react scroll to top upon click react scroll to top with hooks react focus on screen top react onclick scroll to up window scroll to top react js react chrome scroll past top of page react click and get to top div react scroll too bottom scrolltotop react not working scrollto top react router go up in the page react react can scroll past top of page move to top react how to give top in reactjs in js move scroll up in react scroll to top setstate react native make sure a page loads at the top react react native scroll to top react move to top of page reactjs on scroll attach div to top of screne how to add to the top of body react auto scroll to top on react react scroll to top library react scroll to top medium how to scroll to top within the container in react js react button scroll to top add scroll top reactjs react take to top of page react top page scroll to to react on click scroll to top react css scrol to top when rendered react scroll top of page spa react change section or page on scroll button scroll element to top react react obtrusive scrollbar event on scroll top in react Scroll up in a react how to make window always scrolled down on component react clear window scrollto with useeffect(() = window.scrollto(0 0) ) clear window.scrollto with useeffect scroll to top react router button to scroll top top js react scroll top top js react scroll top react scrollTo(0) in react js how to scroll to top in react how to scroll page by word react scroll to top in react how to scroll to top reactjs force view to top of page react scrolltop react js react set scroll to 0 scroll to top of page react React scroll top how to scroll top in react button to go to the top of webpage reactjs croll top in react react js button to go up reactjs scroll to top html button scroll container in div react redux hooks the button go to the top reactjs after click go to the top react back to top in react how to make the screen go on top react why my app always jumps to center of page when i change page react js window.scroll second rendering in middle of page scroll to top react component react back to top windowScroll to top react if i down on page how make to top react function scrolup react react when rendering component divscroll to top of div smooth back to top arrow react back to top arrow react scroll to the top of the component on render scroll to top on page load react scrollTop in functional component on update scrollTop in functional component on componentdidupdate react when page loads scroll to top Scroll to top in react js reacjs not scroll top react scroll to top after reload page create a scroll to top button react how to scroll page to some section after loading inreactjs how to take scrollbar to top in react js make scroll towards end of the page on click event in react app how to set top scroll after click event in react js react floating back to top button react back to top button bact to top react react to top button scroll but tag stay on top in reactJS problem react scroll top page on click react back to top arrow onclick to go to the top of the page in react with hooks onclick to go to the top of the page in react react scroll to the top fix scroll symbol in react hs react window scroll top list react scroll to top of page scroll to top using ref react react use scroll top scroll react and render new component react scroll div to top how to scroll to top of page in react react arrow back to top set scroll to top of page react scroll to top on click reactjs react-scroll to top on click react scroll a div to top react scroll to top div scroll to top a part in react set scroll to top in div in react react scroll tot op scroll up on click react scroll to top a div in react scroll to top open slat in react react scroll up when goes another page scroll to the top react back to top button reactjs how to change page position onclick react how to get top of page on click in react react scroll page to top react js single page website doesnt go to top of the page on load redirect and scroll to height react redirect and scroll to heigth react react show newest posts to top of page react how to add newest posts to top of page react window animated scroll to top hook scroll to location in page with click in react how to scroll top on reload react how to scroll to the top on reload react how to go to top of the page in react js how to make page scroll to the top jsx onclick auto scroll to to top of page react react not scrolling back to the top how to scroll to the top when react component loads how to set after clicking to go on the top of web page in react app REACT TO TOP react scroll to the top back to top reactjs react scroll top on click scroll to top button display react antive scroll to top of window react react native hooks scroll to top scroll to top in react app how to scroll to top on state change indside a inner componentreact how to scroll to top on state change react scroll to top on react scrolltop using react js automatically scroll to top of page react how to scroll to top of component react scroll to top on state change react responsive scrolltop button using react js scroll to top reacr scroll to top button using react js for 600px screen react back to top link react scroll to top on link click scroll to the top in react js react js scroll top implement scroll to top in react js scroll to top list in react on click scroll to top in react on click react js scroll to top how to move to top on click react react scroll to top of component scroll to top react js react js back to top react back to top on click move page up in react js react scroll after component mount react button onclik go to top css scroll top react scrolltotop react back to top button react react scroll up to top of page functionality react focus on top of page show page in react at the top scroll to top on click Link reactjs scroll top of page reactJS scroll top in react js react page scroll to top go to top button in react react make scroll to top button reactjs scroll top scroll to top reactjs react click arrow to scroll scroll to top react on click react component scroll to top go to top of page react how to make react scroll up on new page smooth scroll down react arrowa react move window to top scroll to the top of the list react reactjs fix scroll page top scroll to top of page javascript react hooks scroll to top of page javascript react scroll to top react onpage load scroll to top react all aplication reactjs on component mount scrolling to top when overflow auto reactjs on component remount scrolling to top when overflow auto reactjs on component remount scrolling to top scroll to top in a component in Reacts js how to move to top of page in html on click in react JS add a scrolling on top of react scrollbar reactjs scroll to top react croll page element at top react on link click scroll to top how to not scroll on top when state changes in react scroll back to top react html go to top react onclick scroll to top reactjs scroll to top react scroll to top js react react scroll up on submit smooth scroll to top of page react react scroll page up react click scroll top on enter scroll to top react react scroll to top after render back to top button react js react js scroll to top of page scroll between pages position react react go to top of page react clicking does not scroll to top of page back to top react react scroll to top move page to error message in react js scroll to top on component change react scroll top in react how to create foot top arrow in react js move to top of page while click on link react js react scroll to top of page
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source