In the following example, no-unused-prop-types will flag a non-use of arrayOfObjWithFoo.*.foo:
static PropTypes = {
arrayOfObjWithFoo: PropTypes.arrayOf(
PropTypes.shape({ foo: PropTypes.string.isRequired })
).isRequired
};
render() {
const fooItems = this.props.arrayOfObjWithFoo.map(objWithFoo => {
<Item foo={objWithFoo.foo} />
});
}
Duplicate of #871.
The no-unused-prop-types rule does not support shape props at the moment as such detection is very difficult. If you use shape props, I recommend setting the skipShapeProps option to true on the rule.
Again, this is still a bug. If it doesn't support shape props, it should not warn on them at all.
If you set the skipShapeProps option to true, it should stop warning on all shape props. Is that not working?
I'm saying that if that option is required for the rule to be usable when using shapes, then the rule should never check shapes.
@ljharb That's a valid point. I'll look into whether or not it makes sense to set skipShapeProps to true as a default.
I agree that skipShapeProps should default to true if it can't properly detect usage of props in shape.
The current behavior contradicts the forbid-prop-types rule since that encourages the use of shape instead of object.
@EvNaverniouk any progress here?
@ljharb Just took a few minutes now to look into this but wasn't able to get far. This issue is talking about 2 things:
skipShapeProps to true by default.Don't think there are any further action items on this issue. Can we close?
Seems reasonable.
Most helpful comment
I'm saying that if that option is required for the rule to be usable when using shapes, then the rule should never check shapes.