I have 2 routes using same component (form), one to create new entry and the other to edit. State name has been removed from React Router, I can't just check if this.route.name === 'edit' => fetch(itemAPI).
One option is to write reducer/action to create "edit" state in my redux store, but I was wondering if it's the best practice and if there is an easier way to check where I am in the app (which route).
My routes:
<Route component={ItemNew} path='/items/edit/:id' />
<Route component={ItemNew} path='/items/new' />
In my ItemNew component, I'd like to:
componentDidMount () {
let stateName = this.props.location.state
if(stateName === 'edit') {
this.props.fetchItem() // dispatch API action
}
}