smmoosavi / jsx-xml

Generate xml string from jsx
MIT License
26 stars 5 forks source link

Is there a possibility to insert colons in attribute names? #4

Closed FLE92 closed 5 years ago

FLE92 commented 5 years ago

Hello again, is there any possibility to add attributes with colons like: <Test abc:def="teststring"/> Thanks for help!

FLE92 commented 5 years ago

(Of course it works with lodash, but that's not an ideal solution...)

smmoosavi commented 5 years ago

In JSX syntaxy you can't add colons. but you can pass an object

const Test = 'Test'
const props = { 'abc:def': "teststring" }

const xml = <Test {...props} />

or create object inline

const xml = <Test {...{ 'abc:def': "teststring" }} />
// output: <Test abc:def="teststring"/>
FLE92 commented 5 years ago

Hello again, Many Thanks again for your quick response! This way works perfectly! Your work is a great help to me. Many greetings, FLE92

smmoosavi commented 1 year ago

update: typescript v5.1 will support "Namespaced JSX Attributes". I'm not tested that yet.