Blog Content

  • [React] 새 페이지 렌더링 시 상단에서 시작하기

    Category Programming/JavaScript on 2018. 9. 30. 15:34

    리액트는 새 페이지를 렌더링한 후 스크롤을 맨 위로 올려주지 않는다. 그래서 별도로 컴포넌트를 만들어서 설정해주어야 한다. 먼저 ScrollToTop.js 컴포넌트를 만든다. import React, { Component } from 'react'; import { withRouter } from 'react-router'; class ScrollToTop extends Component { componentDidUpdate(prevProps) { if (this.props.location !== prevProps.location) { window.scrollTo(0, 0) } } render() { return this.props.children } } export default withRouter(S..

    Read more