reactjs / reactjs/react-docgen

Complex composition using `PropTypes.shape`

Ouverte
#255 0 commentaires 6 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Langage dominant
TypeScript
Étoiles
3.8k
Forks
316
Merge moyen
5 h 7 min
PR mergées (30 j)
4

Description

I have a component that looks something along the lines of

import A from './A';
import B from './B';

class MyComponent extends Component {
...
}

MyComponent.propTypes = {
  aProps: PropTypes.shape(A.propTypes),
  bProps: PropTypes.shape(B.propTypes),
  ...
};

Is there a way to make the parser detect that this is a composition rather than simple prop shapes?
I'm doing this because I don't want all the props to live on the wrapper component's scope but to contain each in their own prop, mainly to be able to distinguish what goes where so I don't accidentally pass props that both A and B may have but in reality shouldn't be the same like className, style, children, etc.

I would also like to know if this is possible:

import A from './A';
import VariantOfA from './VariantOfA';

class MyComponent extends Component {
...
}

MyComponent.propTypes = {
  aProps: PropTypes.oneOfType([PropTypes.shape(A.propTypes),PropTypes.shape(VariantOfA.propTypes)])
  ...
};

In this scenario I want to be able to represent with a single prop both A and VariantOfA because essentially they are the same with minor differences in prop types.

I would assume this could be the same for PropTypes.arrayOf and PropTypes.objectOf since they're not that different from PropTypes.oneOfType

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

L’issue ne nomme aucun fichier, test ou point d’entrée du parser. Commencez donc par retracer la manière dont PropTypes.shape, oneOfType, arrayOf et objectOf sont actuellement traités. Comparez les exemples demandés de composants imbriqués et de variantes avec la documentation générée, puis définissez la sortie attendue et les tests avant l’implémentation.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
javascript, react
Domaine
documentation, tooling
Type d'issue
Fonctionnalité
Difficulté
5/5
Temps estimé
Plus d'une semaine
Activité
À l'abandon
Clarté
À clarifier
Accessibilité débutants
25/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.