When copying JSX example code from somewhere to use in my React Python projects, I got tired of having to manually convert JSX code to Python functions with dictionary attributes and having to manually quote everything. So I created this function that will (mostly) do it for me.
For example, this JSX code:
<div id="root"><Button radius="md" size="lg" compact uppercase>Settings</Button></div>
will get converted to this Python code:
Div({'id': 'root'},
Button({'radius': 'md', 'size': 'lg', 'compact': True, 'uppercase': True}, "Settings")
)
pip install git+https://github.com/JennaSys/pyreact-tools
usage: jsxtopy [-h] [-v] [-d] [--test] [--dev] [jsx]
Converts a JSX fragment to a Python function equivalent
positional arguments:
jsx JSX string to convert (If not supplied, will try to use what is in clipboard)
optional arguments:
-h, --help show this help message and exit
-v, --verbose Print original JSX and Python result to console
-d, --dict Create props as dict function instead of dict literal
--test Run JSX unit tests
--dev Run JSX development test