몇가지 hooks가 추가되었다.
React Router는 현재 location(or URL)를 위한 state container이다.
→ location을 업데이트 하기 위한 Link그리고 history API와 같은 관련된 tool을 제공한다.
아래의 글에선 react에 hooks를 적용하면서 어떤 점을 개선할 수 있었는지를 예시를 통해 설명해준다.
import React from 'react'
import ReactDOM from 'react-dom'
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom'
// In the code below, BlogPost is used as both a <Route component>
// and in a <Route render> function. In both cases, it receives a `match`
// prop, which it uses to get the URL params.
function BlogPost({ match }) {
let { slug } = match.params
// ...
}
ReactDOM.render(
<Router>
<div>
<Switch>
{/* Using the `component` prop */}
<Route path="/blog/:slug" component={BlogPost} />
{/* Using the `render` prop */}
<Route
path="/posts/:slug"
render={({ match }) => <BlogPost match={match} />}
/>
</Switch>
</div>
</Router>,
document.getElementById('root')
)
params를 얻기 위해서 기존에 살펴봤던 방식처럼 component composition tricks들을 사용하지 않아도 된다.
→ 단지 children element를 사용하면 됩니다.