no do it like this:

const {match} = this.props;
const {params: {id: userId} = {} } = match || {};


Like @Tarek said, that is the better way to do it. Just to check that the object and its properties are indeed valid.

This is also a good opportunity to check out the optional chaining operator! It is an experimental babel plugin that will (hopefully) be added to ES9!

Check it out here!

This is doing exactly what you would want in a much cleaner and simpler way.

Related Query

More Query from same tag