Skip to content

Commit b824ba8

Browse files
authored
fix(website): Fix ReactLiveScope examples (#3980)
Fixes #3601
1 parent 08ebee5 commit b824ba8

File tree

4 files changed

+51
-30
lines changed

4 files changed

+51
-30
lines changed

benchmark/.eslintrc.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

website/docs/basics/traversing.md

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const $ = cheerio.load(
4949
);
5050

5151
const listItems = $('ul').find('li');
52-
render(`List item count: ${listItems.length}`);
52+
render(<>List item count: {listItems.length}</>);
5353
```
5454

5555
### `children`
@@ -70,7 +70,7 @@ const $ = cheerio.load(
7070
);
7171

7272
const listItems = $('ul').children('li');
73-
render(`List item count: ${listItems.length}`);
73+
render(<>List item count: {listItems.length}</>);
7474
```
7575

7676
### `contents`
@@ -90,7 +90,7 @@ const $ = cheerio.load(
9090
);
9191

9292
const contents = $('div').contents();
93-
render(`Contents count: ${contents.length}`);
93+
render(<>Contents count: {contents.length}</>);
9494
```
9595

9696
## Moving Up the DOM Tree
@@ -115,7 +115,7 @@ const $ = cheerio.load(
115115
);
116116

117117
const list = $('li').parent();
118-
render(list.prop('tagName'));
118+
render(<>{list.prop('tagName')}</>);
119119
```
120120

121121
### `parents` and `parentsUntil`
@@ -145,7 +145,12 @@ const ancestors = $('li').parents();
145145
const ancestorsUntil = $('li').parentsUntil('div');
146146

147147
render(
148-
`Ancestor count (also includes <body> and <html>): ${ancestors.length} | Ancestor count (until <div>): ${ancestorsUntil.length}`,
148+
<>
149+
<p>
150+
Ancestor count (also includes "body" and "html" tags): {ancestors.length}
151+
</p>
152+
<p>Ancestor count (until "div"): {ancestorsUntil.length}</p>
153+
</>,
149154
);
150155
```
151156

@@ -169,7 +174,7 @@ const $ = cheerio.load(
169174
);
170175

171176
const list = $('li').closest('ul');
172-
render(list.prop('tagName'));
177+
render(<>{list.prop('tagName')}</>);
173178
```
174179

175180
## Moving Sideways Within the DOM Tree
@@ -202,7 +207,12 @@ const $ = cheerio.load(
202207
const nextItem = $('li:first').next();
203208
const prevItem = $('li:eq(1)').prev();
204209

205-
render(`Next: ${nextItem.text()} | Prev: ${prevItem.text()}`);
210+
render(
211+
<>
212+
<p>Next: {nextItem.text()}</p>
213+
<p>Prev: {prevItem.text()}</p>
214+
</>,
215+
);
206216
```
207217

208218
## `nextAll`, `prevAll`, and `siblings`
@@ -237,7 +247,11 @@ const prevAll = $('li:last').prevAll();
237247
const siblings = $('li:eq(1)').siblings();
238248

239249
render(
240-
`Next All: ${nextAll.text()} | Prev All: ${prevAll.text()} | Siblings: ${siblings.text()}`,
250+
<>
251+
<p>Next All: {nextAll.text()}</p>
252+
<p>Prev All: {prevAll.text()}</p>
253+
<p>Siblings: {siblings.text()}</p>
254+
</>,
241255
);
242256
```
243257

@@ -270,7 +284,12 @@ const $ = cheerio.load(
270284
const nextUntil = $('li:first').nextUntil('li:last-child');
271285
const prevUntil = $('li:last').prevUntil('li:first-child');
272286

273-
render(`Next: ${nextUntil.text()} | Prev: ${prevUntil.text()}`);
287+
render(
288+
<>
289+
<p>Next: {nextUntil.text()}</p>
290+
<p>Prev: {prevUntil.text()}</p>
291+
</>,
292+
);
274293
```
275294

276295
## Filtering elements
@@ -303,7 +322,7 @@ const $ = cheerio.load(
303322
);
304323

305324
const secondItem = $('li').eq(1);
306-
render(secondItem.text());
325+
render(<>{secondItem.text()}</>);
307326
```
308327

309328
### `filter` and `not`
@@ -332,7 +351,10 @@ const matchingItems = $('li').filter('.item');
332351
const nonMatchingItems = $('li').not('.item');
333352

334353
render(
335-
`Matching: ${matchingItems.text()} | Non-matching: ${nonMatchingItems.text()}`,
354+
<>
355+
<p>Matching: {matchingItems.text()}</p>
356+
<p>Non-matching: {nonMatchingItems.text()}</p>
357+
</>,
336358
);
337359
```
338360

@@ -357,7 +379,7 @@ const $ = cheerio.load(
357379
);
358380

359381
const matchingItems = $('li').has('strong');
360-
render(matchingItems.length);
382+
render(<>{matchingItems.length}</>);
361383
```
362384

363385
### `first` and `last`
@@ -384,7 +406,12 @@ const $ = cheerio.load(
384406
const firstItem = $('li').first();
385407
const lastItem = $('li').last();
386408

387-
render(`First: ${firstItem.text()} | Last: ${lastItem.text()}`);
409+
render(
410+
<>
411+
<p>First: {firstItem.text()}</p>
412+
<p>Last: {lastItem.text()}</p>
413+
</>,
414+
);
388415
```
389416

390417
## Conclusion

website/src/theme/ReactLiveScope/index.js

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React from 'react';
2+
import * as cheerio from '../../../../dist/browser';
3+
4+
// Add react-live imports you need here
5+
const ReactLiveScope = {
6+
cheerio,
7+
React,
8+
...React,
9+
};
10+
11+
export default ReactLiveScope;

0 commit comments

Comments
 (0)