Props.match.params.id undefined but in console, how can I use it in useEffect hook function. I'm using hashRouter

I’ve tried some options I found, like useParams() or other tricks but it’s not working. I think I’m missing something Fundamental. Here is my code

ReactDOM.render(
  <HashRouter>
    <App />
  </HashRouter>,
  document.getElementById("root")
);
function App(){
return(
...
<Switch>
          <Route exact path={["/", "/movies"]} component={MoviesList} />
          <Route exact path="/add" component={AddMovie} />
          <Route path="/movies/:id" component={Movie} />
</Switch>
);
}

Here is my component to use id

export default function Movie(props) {
...
    useEffect(() => {
            getMovie(props.match.params.id);
        }, [props.match.params.id]);
};

I try inside function Movie useParams() and other things. But doesn’t work. When I console.log(props.match.params.id) it appears perfect and in the url also.

32 thoughts on “Props.match.params.id undefined but in console, how can I use it in useEffect hook function. I'm using hashRouter”

Leave a Comment