Skip to content

Commit 884a782

Browse files
committed
Break from JSX-No-React + minor child code improvements
1 parent 019afa3 commit 884a782

File tree

4 files changed

+24
-34
lines changed

4 files changed

+24
-34
lines changed

CHANGELOG.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# 2.1.2
2+
We are now `jsx-standalone` - to continue the minimal approaches of `jsx-no-react` in the past. The previous repo has been archived and abandoned - so this is the new ongoing support.
3+
14
# 2.0.0
25

36
Breaking changes introduced with rendering modes - `renderAndReplace` is now called `render` to follow common practice with SPA frameworks rendering mechanisms. Additionally, the render locations below are more explicit on where they will place the JSX output. Finally, prepend and append now support top-level JSX fragments (before and after render locations require a top-level container element still).
@@ -25,7 +28,7 @@ Sadly the previous release had old code in it, this release fixes it.
2528

2629
This release needs extra care in the babel configuration to make Fragments work.
2730
You need to replace `babel-plugin-transform-react-jsx` with `@babel/preset-react`.
28-
Please check the [README](https://github.com/bitboxer/jsx-no-react/blob/main/README.md)
31+
Please check the [README](https://github.com/jaredsartin/jsx-standalone/blob/main/README.md)
2932
for details.
3033

3134
# 0.5.0

README.md

+10-25
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,11 @@
1-
# jsx-no-react
1+
# jsx-standalone
22

3-
[![Build Status](https://github.com/jaredsartin/jsx-no-react/actions/workflows/node.js.yml/badge.svg?branch=main)](https://github.com/jaredsartin/jsx-no-react/actions/workflows/node.js.yml)
4-
5-
`jsx-no-react` makes it possible to use React's JSX syntax outside of React projects. Using `renderBefore` and `renderAfter` requires a modern browser supporting `Element.insertAdjacentElement()` - all other render modes function in legacy browsers.
3+
`jsx-standalone` makes it possible to use React's JSX syntax outside of React projects. Using `renderBefore` and `renderAfter` requires a modern browser supporting `Element.insertAdjacentElement()` - all other render modes function in legacy browsers.
64

75
## Installation
86

97
```sh
10-
yarn add jsx-no-react
11-
```
12-
13-
### Upgrading
14-
15-
2.0.0 introduces breaking changes with rendering modes - `renderAndReplace` is now called `render` to follow common practice with SPA frameworks rendering mechanisms. Additionally, the render locations below are more explicit on where they will place the JSX output. Finally, prepend and append now support top-level JSX fragments (before and after render locations require a top-level container element still).
16-
17-
New methods:
18-
```js
19-
renderBefore(<Hello name="world" />, targetElement);
20-
renderPrepend(<Hello name="world" />, targetElement);
21-
render(<Hello name="world" />, targetElement);
22-
renderAppend(<Hello name="world" />, targetElement);
23-
renderAfter(<Hello name="world" />, targetElement);
8+
yarn add jsx-standalone
249
```
2510

2611
### Usage in Babel
@@ -57,10 +42,10 @@ Details on how to inject jsxElem as builder can be found [in the esbuild documen
5742

5843
### Basic
5944

60-
The `jsx-no-react` package just defines a function to replace the `React.createElement`, so as well as importing the relevant function into scope where you want to use JSX:
45+
The `jsx-standalone` package just defines a function to replace the `React.createElement`, so as well as importing the relevant function into scope where you want to use JSX:
6146

6247
```javascript
63-
import jsxElem, { render } from "jsx-no-react";
48+
import jsxElem, { render } from "jsx-standalone";
6449

6550
function App(props) {
6651
return <div>Hello {props.name}</div>;
@@ -72,7 +57,7 @@ render(<App name="world" />, document.body);
7257
or
7358

7459
```javascript
75-
import jsxElem, { render } from "jsx-no-react";
60+
import jsxElem, { render } from "jsx-standalone";
7661

7762
function App(name) {
7863
return <div>Hello {name}</div>;
@@ -117,7 +102,7 @@ When rendering a component JSX attributes will be passed as single object.
117102
For example:
118103

119104
```javascript
120-
import jsxElem, { render } from "jsx-no-react";
105+
import jsxElem, { render } from "jsx-standalone";
121106

122107
function Hello(props) {
123108
return <h1>Hello {props.name}</h1>;
@@ -134,7 +119,7 @@ There are several ways to render an element:
134119
- `renderAfter`: this function renders the JSX element after after the target element - top level JSX element must not be a fragment.
135120

136121
```javascript
137-
import jsxElem, { render, renderAfterEnd, renderBeforeEnd, renderAndReplace } from "jsx-no-react";
122+
import jsxElem, { render, renderAfterEnd, renderBeforeEnd, renderAndReplace } from "jsx-standalone";
138123

139124
function Hello(props) {
140125
return <h1>Hello {props.name}</h1>;
@@ -152,7 +137,7 @@ renderAfter(<Hello name="world" />, document.body);
152137
Components can be reused and combined together.
153138

154139
```javascript
155-
import jsxElem, { render } from "jsx-no-react";
140+
import jsxElem, { render } from "jsx-standalone";
156141

157142
function Hello(props) {
158143
return <h1>Hello {props.name}</h1>;
@@ -293,7 +278,7 @@ function App() {
293278
Object can be passed to the `style` attribute with keys in camelCase.
294279

295280
```javascript
296-
import jsxElem, { render } from "jsx-no-react";
281+
import jsxElem, { render } from "jsx-standalone";
297282

298283
function Hello(props) {
299284
return <h1>Hello {props.name}</h1>;

package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
2-
"name": "jsx-no-react",
3-
"version": "2.1.0",
2+
"name": "jsx-standalone",
3+
"version": "2.1.2",
44
"description": "Use JSX without React",
5-
"repository": "https://github.com/bitboxer/jsx-no-react",
6-
"author": "Terry Kerr <[email protected]>",
5+
"repository": "https://github.com/jaredsartin/jsx-standalone",
6+
"author": "Jared Sartin <[email protected]>",
77
"contributors": [
88
"Bodo Tasche <[email protected]>",
99
"Matteo Barison <[email protected]>",
10-
"Jared Sartin <[email protected]>"
10+
"Terry Kerr <[email protected]>"
1111
],
1212
"license": "MPL-2.0",
1313
"private": false,

src/module.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,18 @@ function converter(tag, attrs, ...children) {
116116
}
117117

118118
const handledAsFunc = typeof tag === 'function' && typeof tag?.name === 'string' && tag?.name !== 'Fragment';
119+
119120
if (handledAsFunc) {
120121
attrs = attrs || {};
121122
attrs.children = children;
122-
children = [];
123123
}
124124

125125
const elem = createElement(tag, attrs);
126126

127-
for (const child of children) {
128-
appendChild(elem, child);
127+
if (!handledAsFunc) {
128+
for (const child of children) {
129+
appendChild(elem, child);
130+
}
129131
}
130132

131133
return elem;

0 commit comments

Comments
 (0)