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
Advertisement
Answer
you should use useParams
import { useParams } from 'react-router-dom';
const { id } = useParams();
or in class component
const id = this.props.match.params.id;