3 ms·
Ask HN: Automate Rewrite of JSX
The project I'm on has used a UI library, and is now thoroughly locked in and I cannot stand it.
I would like to be able to write a script that will go through the codebase and change code without having to do the onerous job of doing it all by hand.
It would be working basically like if I could write XSLT to rewrite JSX.
So if I had some components like
<Button
variant="outline"
w="100%"
onClick={() => push(getPagePathByLocale(shoppingBagPage, locale))}
>
{microcopies[CommonCMS.button.shoppingBag]} ({cart?.totalLineItemQuantity})
</Button>
then one could write code like (pseudo)
match = Button
className = apply-templates match="@*" mode = "className"
return <Button className="outline big" onClick={() => push(getPagePathByLocale(shoppingBagPage, locale))}>{microcopies[CommonCMS.button.shoppingBag]} ({cart?.totalLineItemQuantity})</Button>
- bryanrasmussen 3y agoobviously in the interest of saving time I have not written the example code to handle the actual className generating.