Will Black
Will Black

Reputation: 402

send id (or get id from router path)

I got simple blog (react/redux) (only frontend part). With user registration and articles. And stuck when tryed to send id to editor. I have same form, but different path for add new and for edit existing article:

<Route path="/add" component={ !currentUser ? Login : ArticleEditor } />
<Route path="/article/:id/edit" component={ !currentUser ? Login : ArticleEditor } />

it might be simple but I have no idea how to send(or get) id to ArticleEditor component to fill form. Plz help if you have good knowledge in React/Redux.

here is the code: https://codesandbox.io/s/twilight-resonance-d9tu6

Upvotes: 1

Views: 361

Answers (1)

Yoel
Yoel

Reputation: 7985

you should use useParams

import { useParams } from 'react-router-dom';
  const { id } = useParams();

or in class component

const id = this.props.match.params.id;

Upvotes: 1

Related Questions