Skip to content

Commit a5b93b9

Browse files
committed
update README.md
1 parent e15c3f9 commit a5b93b9

File tree

2 files changed

+42
-24
lines changed

2 files changed

+42
-24
lines changed

README.md

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
</p>
1515

1616
**React Live** brings you the ability to render React components with editable source code and live preview.
17-
It supports server-side rendering and comes in a tiny bundle.
1817

1918
The library is structured modularly and lets you style and compose its components freely.
2019

@@ -48,17 +47,30 @@ import {
4847

4948
### How does it work?
5049

51-
It takes your code and transpiles it with [Bublé](https://github.com/bublejs/buble), while the code is displayed using [`react-simple-code-editor`](https://github.com/satya164/react-simple-code-editor) and the code is highlighted using [`prism-react-renderer`](https://github.com/FormidableLabs/prism-react-renderer).
50+
It takes your code and transpiles it with [Sucrase](https://github.com/alangpierce/sucrase), while the code is displayed using [`use-editable`](https://github.com/FormidableLabs/use-editable) and the code is highlighted using [`prism-react-renderer`](https://github.com/FormidableLabs/prism-react-renderer).
5251

5352
The transpiled code is then rendered in the preview component (`LivePreview`), which does a fake mount if the code
5453
is a React component.
5554

55+
Prior to `v3.0.0`, earlier versions of the library used different internals. We recommend using the latest version you can.
56+
57+
|Version|Supported React version|Editor |Transpiler
58+
|-------|-----------------------|--------------------------|----------
59+
|v3.x.x |v17.x.x |`use-editable` |`Sucrase`
60+
|v2.x.x |v16.x.x |`react-simple-code-editor`|`Bublé`
61+
62+
Please see also the related Formidable libraries:-
63+
64+
- [https://github.com/FormidableLabs/prism-react-renderer](https://github.com/FormidableLabs/prism-react-renderer)
65+
- [https://github.com/FormidableLabs/use-editable](https://github.com/FormidableLabs/use-editable)
66+
5667
### What code can I use?
5768

5869
The code can be one of the following things:
5970

6071
- React elements, e.g. `<strong>Hello World!</strong>`
6172
- React pure functional components, e.g. `() => <strong>Hello World!</strong>`
73+
- React functional components with Hooks
6274
- React component classes
6375

6476
If you enable the `noInline` prop on your `LiveProvider`, you’ll be able to write imperative code,
@@ -122,6 +134,28 @@ const code = `
122134
</LiveProvider>
123135
```
124136

137+
### Using Hooks
138+
139+
React Live supports using Hooks, but you may need to be mindful of the scope. As mentioned above, only React is injected into scope by default.
140+
141+
This means that while you may be used to destructuring `useState` when importing React, to use hooks provided by React in React Live you will either need to stick to using `React.useState` or alternately you can set the scope up so that `useState` is provided separately.
142+
143+
```js
144+
() => {
145+
const [likes, increaseLikes] = React.useState(0);
146+
147+
return (
148+
<>
149+
<p>
150+
{`${likes} likes`}
151+
</p>
152+
<button onClick={() => increaseLikes(likes + 1)}>Like</button>
153+
</>
154+
);
155+
}
156+
```
157+
158+
125159
### What bundle size can I expect?
126160

127161
Our reported bundle size badges don't give you the full picture of
@@ -132,16 +166,7 @@ on.
132166
<img src="https://img.badgesize.io/https://unpkg.com/react-live/dist/react-live.min.js?compression=gzip&label=gzip%20size">
133167

134168
In an actual app when you use `react-live` you will also be bundling
135-
Buble for transpilation, which adds `~135kB` to your bundle. This also
136-
includes their dependency on `regenerate-unicode-properties`, which
137-
is rather large as well.
138-
139-
We maintain a fork of Buble which excludes the ESnext Regular Expression
140-
transpilation with removes Buble's large dependency and weighs in at
141-
a smaller size of `~51kB`, which you can find published at [`@philpl/buble`](https://npm.im/@philpl/buble).
142-
143-
You can alias this in Webpack or the build tool of your choice, which
144-
will reduce the overall bundle size of `react-live` to about `83kB`.
169+
Sucrase for transpilation.
145170

146171
## API
147172

@@ -216,14 +241,9 @@ The component wrapped with `withLive` gets injected the following props:
216241
217242

218243
## FAQ
219-
> **I want to use experimental feature x but Bublé doesn't support it! Can I use babel instead?**
220-
221-
`react-live` doesn't currently support configuring the transpiler and it ships with Bublé. The current workaround for using some experimental features `bublé` doesn't support would be to use the `transformCode` prop on `LiveProvider` to transform your code with `babel` alongside `bublé`.
222-
223-
Here is a minimal example on how you could use `babel` to support class-properties in `react-live`:
224-
244+
> **I want to use experimental feature x but Sucrase doesn't support it! Can I use babel instead?**
225245
226-
[![Edit 7ml9mjw766](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/7ml9mjw766?fontsize=14)
246+
`react-live` doesn't currently support configuring the transpiler and it ships with Sucrase. The current workaround for using some experimental features `Sucrase` doesn't support would be to use the `transformCode` prop on `LiveProvider` to transform your code with `babel` alongside `Sucrase`.
227247

228248

229249

@@ -238,12 +258,11 @@ Here's a high-level decision tree:
238258

239259
Here are the various factors at play:
240260

241-
- **Build**: `component-playground` uses `babel-standalone`, `react-live` uses `bublé`. (_Note_: `react-live` might make transpiler customizable in the future).
261+
- **Build**: `component-playground` uses `babel-standalone`, `react-live` uses `Sucrase`.
242262
- **Bundle size**: `component-playground` has a larger bundle, but uses a more familiar editor setup. `react-live` is smaller, but more customized editor around `prism`.
243263
- **Ease vs. flexibility**: `react-live` is more modular/customizable, while `component-playground` is easier/faster to set up.
244-
- **SSR**: `component-playground` is not server-side renderable, `react-live` is.
245264
- **Extra features**: `component-playground` supports raw evaluation and pretty-printed output out-of-the-box, while `react-live` does not.
246-
- **Error handling**: `component-playground` might have more predictable error handling than `react-live` in some cases (due to `react-dom`, although this might change with React 16).
265+
- **Error handling**: `component-playground` might have more predictable error handling than `react-live` in some cases (due to `react-dom`).
247266

248267
## Maintenance Status
249268

demo/components/Header.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ const Header = () => (
9898

9999
<Description>
100100
<div>
101-
Easily render live editable React components with server-side rendering
102-
support and a tiny bundle size, thanks to Bublé and a Prism.js-based
101+
Easily render live editable React components thanks to Sucrase and a Prism.js-based
103102
editor.
104103
</div>
105104

0 commit comments

Comments
 (0)