Open Intaria opened 1 year ago
Attributes are HTML attributes, which are lowercase.
If you are converting an HTML element into a React component, you'll need to remap it to props manually.
Then is it possible to pass raw attributes too in HTMLElement node?
Not sure I follow? Just do this:
const onTransform = (node: HTMLElement, children: Node[]): ReactNode => {
const attributes = {}
node.attributes.map((item) => {
attributes[item['name']] = item['value']
})
// this
attributes.className = attributes.classname;
switch (node.tagName) {
case 'a':
return (
<Link {...attributes}>{children}</Link>
)
case 'img':
return (
<Image {...attributes} />
)
default:
return undefined
}
}
I am trying to create an HOC component. For it i need the ability to forward any attributes to the tag.
The problem is that there are a lot of options in react, which can be different: className, tabIndex, defaultChecked, itemScope, itemType, etc. And listing them all by hand seems like a crutch
You only need to write this once, it's only a couple of lines. This won't be changing.
Good afternoon. Can you please tell me why interweave transforms all attributes to lowercase?
I am trying to do something like this, for not to describe each attribute by hand:
And got this:
Warning: Invalid DOM property `classname`. Did you mean `className`?