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:
JavaScript
x
3
1
<Route path="/add" component={ !currentUser ? Login : ArticleEditor } />
2
<Route path="/article/:id/edit" component={ !currentUser ? Login : ArticleEditor } />
3
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
Advertisement
Answer
you should use useParams
JavaScript
1
2
1
import { useParams } from 'react-router-dom';
2
JavaScript
1
2
1
const { id } = useParams();
2
or in class component
JavaScript
1
2
1
const id = this.props.match.params.id;
2