Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/follgad/vanilla-jsx


https://github.com/follgad/vanilla-jsx

Last synced: 26 days ago
JSON representation

Awesome Lists containing this project

README

        

# JSX to JS — Use JSX without react

[https://mikofilas.netlify.app/blog/jsx-without-react](https://mikofilas.netlify.app/blog/jsx-without-react)

## Installation and setup

```bash
$ npm i jsx2js @babel/plugin-transform-react-jsx
```

Edit `babel.config.js` or `.babelrc`:

```js
{
// ...
"plugins": [
// ...
[
"@babel/plugin-transform-react-jsx",
{
"runtime": "automatic",
"importSource": "jsx2js"
}
]
]
}
```

Now you're ready to start writing JSX!

## Example

```jsx
const ExampleComponent = ({
children,
title = 'Default title',
...props
}) => {
return (


{title}


{children}


);
};

const Counter = ({}) => {
let clicks = 0
const clickSpan = 0
const increment = () => {
clicks++
clickSpan.innerText = clicks
}
const button = (

Clicked {clickSpan} times

)
button.addEventListener("click", increment)

return button
}

document.body.append(



Example child


It just works



)
```

Demo here: https://codesandbox.io/s/nostalgic-architecture-kv47z?file=/src/index.jsx