Hooks - useHistory를 이용한 페이지 이동

마크튠·2021년 9월 20일
0
post-thumbnail

1. useHistory()

import { useHistory } from 'react-router-dom';

export default function Button() {
  const history = useHistory();
  function click() {
      history.push("/");
  }
  
  return <button onClick={click}>버튼</button>
}

라우팅에 필요한 history
withRouter 의 도움 없이 사용하게 해주는 Hook 입니다.

profile
React, GraphQL, NodeJs

0개의 댓글