Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Use class list and implicit ... identifier #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sebmarkbage
Copy link
Contributor

className : string -> classList : array

Objects and arrays could use an implicit ... identifier for deep updates. It's not yet clear how a deep update strategy would work in post-ES7 but this could be one way.

@sophiebits
Copy link
Member

What does {...a, ...b, classList: [..., 'green']} destructure into?

@sebmarkbage
Copy link
Contributor Author

I assume you mean desugar in the context of an object initializer (as opposed to a destructuring statement).

This is not real syntax and not yet part of the ES7 proposal. In this hypothetical proposal, it would desugar to the following ES6:

(
temp = Object.assign({}, a, b),
temp.classList = [...temp.classList, 'green'],
temp
)

@sophiebits
Copy link
Member

Sorry, yes – an object initializer. Thanks.

@radubrehar
Copy link

I'm also for supporting array in classList.

Initially I was for adding array support in className, but I am now aware of the problems that can occur in code expecting className to be a string, and getting an array instead.

So I think a better solution would be the proposed classList property, which could then deprecate the className property. Under the hood, whenever React detects some value in className, it should both warn about deprecation and also copy the value in classList. A benefit of this would also be popularizing the lesser known/used classList dom method.

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

Successfully merging this pull request may close these issues.

4 participants