ryansolid / dom-expressions

A Fine-Grained Runtime for Performant DOM Rendering
MIT License
874 stars 125 forks source link

JSX attribute types #322

Closed chiefcll closed 3 months ago

chiefcll commented 5 months ago

I have a universal renderer where I can do something like:

<Tile width={35} height={26} x={475} y={78} radius={62}/>

And that works great and all the attributes are numbers.

However if a user does this:

<Tile width="35" height="26" x="475" y="78" radius="62" />

It's valid but all the types come in as strings.

Question: Can I specify certain attributes to be treated as Numbers during compilation?

ryansolid commented 3 months ago

Hmm.. we don't have the option right now as it is pretty specific. In the DOM we are used to everything being strings so we get away with it and JSX passes it straight through like that so we don't need any sort of special processing. It would also need to be handled on the spread side at runtime since we don't see all the attributes coming in that way. I could see how an option like this could be made/work just unsure about edge cases and it making sense.

chiefcll commented 3 months ago

Just figured I'd ask. Ideally I'd want it done during build for less processing client side. I could have something custom in Vite to look for certain properties and switch them.