Within mapStateToProps, how to obtain a react-router param?

If your using react router, just use this.props.params.id.

this depends on how you defined the router though. if your router is like

<route path = `/skills/:id` component = {yourComponent} />

then it works. but if your router is like

<route path = `/skills/:number` component = {yourComponent} />

then you have to do this.props.params.number


so what you would want to do is map skill_id in mapStateToProps to the value that is stored in the state from react-router. Then you would just bring in skill_id

Also I would recommend some logic just to check if skill_id is undefined as that key only is generated in the object if the user has a value for the skill_id

 constructor(props) {
  super(props);
  this.state = { skill_id: props.skill_id };
}

....

const mapStateToProps = (state, ownProps) => {
  return {
     skill_id: (('skill_id' in state.routing.locationBeforeTransitions.query) ? state.routing.locationBeforeTransitions.query.skill_id: false),
     ratingsBySkillId: state.rating.by_skill_id.find(el => el.skill_id === skill_id)
  };
};

Hopefully that helps but your value should be in the routing object of the state


This ended up working:

const mapStateToProps = (state, ownProps) => {
  const skill_id = ownProps.match.params.skill_id;
....