reactjs / reactjs/react.dev

Document how React treats different attributes

Aberta
#80 13 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

difficulty: medium good first issue in-progress type: documentation
Linguagem predominante
JavaScript
Estrelas
11.8k
Forks
7.9k
Merge médio
1d 11h
PRs com merge (30d)
11

Descrição

This issue was originally reported by @MMeent via facebook/react/issues/9220

Please refer to the original issue for the related discussion thread.

Text of original issue:

As of #9106 there are quite a lot of tests for HTML's boolean properties on tags. According to these tests HTML properties should get rendered into empty strings or not set, e.g. <div hidden={true} /> should render to <div hidden="" /> and <div hidden={false} /> should render to <div />.

But when I look further, there are other tests which do similar things: <a href={true} /> should render to <a href="true" />. This means that if I take true as my property value, I will not know what the result will be.

The issue being: React currently does not have a clearly-defined and documented way with which they handle their props. Could the docs be updated to specify which type of prop will result in what? e.g. "any number gets parsed to a string (using Number.toString()), an object gets stringified by using arg => Object.entries(arg).map(([key, val]) => ${key}: ${val};).join(), and booleans toggle the property."

In short, these are the bugs/undocumented features/contradictions that the tests expect to happen, plus my expectations:

  • prop={true} gets parsed to prop="" or prop="true" for select properties
    expected: either prop="" or prop="prop", not both // as per checked=checked HTML standard
  • prop="" gets parsed as prop="" or
    expected: prop=""
  • prop="prop" might get parsed as either prop="prop", prop="" or even
    expected: prop="prop"
  • prop="foo" => prop="" or prop="foo"
    expected: prop="foo"
  • prop={false} => or prop="false"
    expected:
  • prop={['foo', 'bar']} => prop="" or prop="foo,bar" (hand-tested, no automatic test available)
    expected: prop="foo bar"
  • prop={{foo: 'bar', baz: 5}} => prop="" or prop="foo: bar; baz: 5;" or prop="[object Object]" (hand-tested, no automatic test available)
    expected: prop="foo: bar; baz: 5" // as per style object transform

Hacky showcase: https://jsfiddle.net/ox8a7vfe/3/

Are these features or are these bugs?

If they are bugs, and work is going to be done on the props value parsing, then the following might be a nice addition:

  • prop={{foo: true, bar: true, baz: false}} => prop="foo bar" // render all true keys, disregard false keys, like classNames.

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Direção de pesquisa

Comece pela discussão original de facebook/react/issues/9220 e pelos casos referenciados ReactDOMServerIntegration-test.js e ReactDOMComponent-test.js. Compare o comportamento documentado com os exemplos e testes e, em seguida, atualize a documentação do React para que o tratamento de valores de atributos seja especificado claramente e os casos listados tenham orientações consistentes.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
javascript, react
Domínio
documentation
Tipo de issue
Documentação
Dificuldade
4/5
Tempo estimado
3-5 dias
Status de atividade
Pouca atividade
Clareza
Razoavelmente clara
Facilidade para iniciantes
35/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.