You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+41-22Lines changed: 41 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,6 @@
14
14
</p>
15
15
16
16
**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.
18
17
19
18
The library is structured modularly and lets you style and compose its components freely.
20
19
@@ -48,17 +47,30 @@ import {
48
47
49
48
### How does it work?
50
49
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).
52
51
53
52
The transpiled code is then rendered in the preview component (`LivePreview`), which does a fake mount if the code
54
53
is a React component.
55
54
55
+
Prior to `v3.0.0`, earlier versions of the library used different internals. We recommend using the latest version you can.
- React elements, e.g. `<strong>Hello World!</strong>`
61
72
- React pure functional components, e.g. `() => <strong>Hello World!</strong>`
73
+
- React functional components with Hooks
62
74
- React component classes
63
75
64
76
If you enable the `noInline` prop on your `LiveProvider`, you’ll be able to write imperative code,
@@ -122,6 +134,28 @@ const code = `
122
134
</LiveProvider>
123
135
```
124
136
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.
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.
145
170
146
171
## API
147
172
@@ -216,14 +241,9 @@ The component wrapped with `withLive` gets injected the following props:
216
241
217
242
218
243
## 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?**
`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`.
227
247
228
248
229
249
@@ -238,12 +258,11 @@ Here's a high-level decision tree:
238
258
239
259
Here are the various factors at play:
240
260
241
-
-**Build**: `component-playground` uses `babel-standalone`, `react-live` uses `bublé`. (_Note_: `react-live` might make transpiler customizable in the future).
-**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`.
243
263
-**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.
245
264
-**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`).
0 commit comments