Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Attributes with the same name as their value #148

Closed
platonlukyanov opened this issue Apr 3, 2022 · 1 comment
Closed

Proposal: Attributes with the same name as their value #148

platonlukyanov opened this issue Apr 3, 2022 · 1 comment

Comments

@platonlukyanov
Copy link

platonlukyanov commented Apr 3, 2022

Hi, this problem was searched on stackoverflow already. To me, code presented in stackoverflow answers look quite ugly.

We had a similar syntax inconvenience in JavaScript language and must have used syntax like this:

return {
    name: name,
    text: text,
    content: content,
}

When the ES6 came we got the modern syntax and opportunity to make our code neater.

return {
    name,
    text,
    content,
}

Problem
Still in JSX this problem is actual.
For example, we have a bunch of variables from props, inner variables and state. They all have the same name with props of childrean components. But passing these props looks gigantic.

function ArticleDetails({ text, color }) {
    const [draft, setDraft] = useState(false);
    const today = new Date.now();
    return (
        <div>
               <ArticleHeader color={color} />
               <ArticleContent  draft={draft} today={today} text={text}/>
       </div>
    )
}

Suggestion
Implement prop, syntax

...
<div>
       <ArticleHeader color, />
       <ArticleContent  draft, today, text,/>
</div>
@platonlukyanov platonlukyanov changed the title Proposal: React's props with the same name as their value Proposal: Attributes with the same name as their value Apr 3, 2022
@NekR
Copy link

NekR commented Apr 3, 2022

What you're suggesting is a boolean value already.

There is a better proposal already: #23

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants