vadimdemedes/dom-chef

Support camelCase props

Open

#72 opened on Sep 28, 2020

View on GitHub
 (0 comments) (1 reaction) (0 assignees)TypeScript (13 forks)github user discovery
bughelp wanted

Repository metrics

Stars
 (531 stars)
PR merge metrics
 (PR metrics pending)

Description

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);
}

Contributor guide