jsx-eslint/eslint-plugin-react

no-unused-prop-types rule does not recognise component that returns an array

Open

#1682 aperta il 8 feb 2018

Vedi su GitHub
 (6 commenti) (2 reazioni) (0 assegnatari)JavaScript (2797 fork)batch import
enhancementhelp wantedreact 16

Metriche repository

Star
 (8630 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

Example:

import React from 'react';
import PropTypes from 'prop-types';

const TestComponent = () => (
  ['one', 'two', 'three'].map(text => <div>{ text }</div>)
);

TestComponent.propTypes = {
  customClass: PropTypes.string,
};

export default TestComponent;

React 16 allows for arrays to be returned from components, but in the above example, the no-unused-prop-types seems to not recognise that customClass is unused. It does detect it when the component is changed to:

const TestComponent = () => {
  const componentArr = ['one', 'two', 'three'].map(text => <div>{ text }</div>);
  return <div>{ componentArr }</div>;
};

Guida contributor