Skip to content

Commit da0632b

Browse files
committed
docs: update README
1 parent 53b053e commit da0632b

File tree

3 files changed

+31
-29
lines changed

3 files changed

+31
-29
lines changed

packages/core/README.md

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,8 @@ createRoot(document.getElementById('root')).render(content);
137137

138138
## JSX
139139
JSX is a syntax extension for JavaScript that lets you write HTML-like markup inside a JavaScript file.
140-
You can use it:
141140

142-
### via `jsx-runtime`
141+
### `jsx-runtime`
143142

144143
In your `tsconfig.json`, you must add these rows:
145144

@@ -153,28 +152,6 @@ In your `tsconfig.json`, you must add these rows:
153152
```
154153
The necessary functions will be automatically imported into your code.
155154

156-
If for some reason you don't want to use auto-imports, then you should use a different approach.
157-
158-
### via `h`
159-
160-
This is the function you need to enable JSX support. In your `tsconfig.json`:
161-
162-
```json
163-
{
164-
"compilerOptions": {
165-
"jsx": "react",
166-
"jsxFactory": "h",
167-
"jsxFragmentFactory": "Fragment"
168-
}
169-
}
170-
```
171-
172-
In this case, you will always have to import the `h` function and the `Fragment` component yourself.
173-
174-
```tsx
175-
import { h, Fragment } from '@dark-engine/core';
176-
```
177-
178155
```tsx
179156
const content = (
180157
<>
@@ -228,7 +205,7 @@ return (
228205
);
229206
```
230207

231-
or just
208+
or
232209

233210
```tsx
234211
return (
@@ -437,7 +414,6 @@ const [albums, setAlbums] = useState<Array<Album>>([]);
437414
useEffect(() => {
438415
fetch('https://jsonplaceholder.typicode.com/albums')
439416
.then(x => x.json())
440-
.then(x => x.slice(0, 10))
441417
.then(x => setAlbums(x));
442418
}, []);
443419

@@ -567,7 +543,7 @@ As the second argument, it takes a function that answers the question of when to
567543
const Memo = memo(Component, (prevProps, nextProps) => prevProps.color !== nextProps.color);
568544
```
569545

570-
#### `Guard`
546+
#### `<Guard />`
571547

572548
A component that is intended to mark a certain area of the layout as static, which can be skipped during updates. Based on `memo`.
573549

@@ -643,10 +619,34 @@ const App = component(() => {
643619

644620
When you get an error, you can log it and show an alternate user interface.
645621

622+
#### `<ErrorBoundary />`
623+
624+
Catching errors is only enabled on the client, and is ignored when rendering on the server. This is done intentionally, because on the server, when rendering to a stream, we cannot take back the HTML that has already been sent.
625+
626+
```tsx
627+
const Broken = component(() => {
628+
throw new Error();
629+
});
630+
631+
const App = component(() => {
632+
return (
633+
<>
634+
<div>I'm OK 🙃</div>
635+
<ErrorBoundary fallback={<div>Ooops! 😳</div>}>
636+
<Broken />
637+
</ErrorBoundary>
638+
<div>I'm OK too 😘</div>
639+
</>
640+
);
641+
});
642+
```
643+
644+
`<ErrorBoundary />` also has a `renderFallback` and `onError` prop.
645+
646646
#### `useError`
647647

648648
```tsx
649-
const Counter = component<{ count: boolean }>(({ count }) => {
649+
const Counter = component<{ count: number }>(({ count }) => {
650650
if (count === 3) {
651651
throw new Error('oh no!');
652652
}
@@ -834,7 +834,7 @@ const [a, b] = useStore([a$, b$]);
834834

835835
## Code splitting
836836

837-
#### `lazy` and `Suspense`
837+
#### `lazy` and `<Suspense />`
838838

839839
If your application is structured into separate modules, you may wish to employ lazy loading for efficiency. This can be achieved through code splitting. To implement lazy loading for components, dynamic imports of the component must be wrapped in a specific function - `lazy`. Additionally, a `Suspense` component is required to display a loading indicator or skeleton screen until the module has been fully loaded.
840840

packages/core/src/boundary/boundary.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const ErrorBoundary = component<ErrorBoundaryProps>(
3131
const [error, reset] = useError();
3232

3333
useEffect(() => {
34+
if (!error) return;
3435
detectIsFunction(onError) && onError(error);
3536
}, [error]);
3637

packages/core/src/start-transition/start-transition.spec.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ describe('@core/start-transition', () => {
177177
await sleep(1);
178178
expect(host.innerHTML).toBe(content(0, true));
179179

180+
// Jest drives me crazy here
180181
// setIdx(1);
181182
// await sleep(1);
182183
// expect(host.innerHTML).toBe(content(1));

0 commit comments

Comments
 (0)