vadimdemedes/dom-chef

Support camelCase props

Open

#72 aperta il 28 set 2020

Vedi su GitHub
 (0 commenti) (1 reazione) (0 assegnatari)TypeScript (13 fork)github user discovery
bughelp wanted

Metriche repository

Star
 (531 star)
Metriche merge PR
 (Metriche PR in attesa)

Descrizione

dom-chef sets the attributes:

https://github.com/vadimdemedes/dom-chef/blob/99adeb64de6eefbc5ccd7fecd449d34c4153c291/index.ts#L77

but as far as I know JSX works with properties, not attributes: https://reactjs.org/docs/dom-elements.html#all-supported-html-attributes

This specifically breaks SVG attributes like: <line strokeWidth={1}> It could be written as <line stroke-width={1}> but then you'd also have to customize the TypeScript types

I think the code should be changed to set the property if it's available, but I don't know if this is "magic". React likely has a list of properties instead (I'd rather not have that)

if (name in element) {
  element[name] = value;
} else {
  element.setAttribute(name, value);
}

Guida contributor