profile
viewpoint

Ask questionsuseParams and other new hooks are not exported in react-router-dom & react-router

Version

"react-router-dom": "^5.1.0", "react-scripts": "3.1.1", (CRA)

Steps to reproduce

Copied from https://reacttraining.com/blog/react-router-v5-1/:

import { BrowserRouter as Router, Route, Switch, useParams } from 'react-router-dom'

function BlogPost() {
  let { slug } = useParams();
  // ...
}

ReactDOM.render(
  <Router>
    <div>
      <Switch>
        {/* No weird props here, just use
            regular `children` elements! */}
        <Route path="/posts/:slug">
          <BlogPost />
        </Route>
      </Switch>
    </div>
  </Router>,
  document.getElementById('root')
)

Expected Behavior

The slug variable should be initialized with the actual slug ID from the slug ID parameter of a given URL.

Actual Behavior

Error:

Attempted import error: 'useParams' is not exported from 'react-router-dom'.

ReactTraining/react-router

Answer questions olalonde

I'm having same issue

useful!

Related questions

Route is not exported in react-router-dom
Cannot read property &#39;location&#39; of undefined at useLocation hot 4
Error: Invariant failed: You should not use <Switch> outside a <Router> hot 3
Replace componentWillMount by UNSAFE_componentWillMount for v3 hot 3
Failed prop type: Invalid prop 'component' supplied to 'Route': the prop is not a valid React component hot 2
Prompt in React 16 "Warning: A history supports only one prompt at a time" hot 1
Use new forwardRef API in withRouter HOC hot 1
Fix <Route children> hot 1
Route is not exported in react-router-dom hot 1
bug: react router dom 4.3.1 pulling react-router 4.4.0 changes after latest publish hot 1
[React.memo] Warning: Failed prop type: Invalid prop `component` of type `object` supplied to `Route`, expected `function` hot 1
Receiving ESM Error but not using ESM hot 1
useParams returns empty object when used outside of Route hot 1
Add useRouter Hook - react-router hot 1
bug: react router dom 4.3.1 pulling react-router 4.4.0 changes after latest publish hot 1
Github User Rank List