react-future
react-future copied to clipboard
Use class list and implicit ... identifier
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.
What does {...a, ...b, classList: [..., 'green']} destructure into?
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
)
Sorry, yes – an object initializer. Thanks.
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.