# useParams, useHistory, useLocaiton (React Hooks)

# useParams

기존에는 Route로 사용되지 않는 컴포넌트에서 props.match, props.history, props.location에 접근하기 위해서는 withRouter를 사용했지만 React hooks의 useParams을 통해서 match.params에 손쉽게 접근할 수 있게 되었다.

import { useParams } from "react-router";

export default function Add() {
  const { id } = useParams();
  // ...
}

# useHistory

useHistory 역시 useParams와 같이 withRouter를 사용하지 않고 history 객체에 접근하게 해주는 React Hook이다.

import { useHistory } from "react-router";

export default function Add() {
  const history = useHistory();
  // ...
}

# useLocation

useLocationwithRouter없이 location 객체에 접근할 수 있게 해주는 Hook이다.

import { useLocation } from "react-router";

export default function Add() {
  const location = useLocation();
  // ...
}