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: packages/preact/README.md
-29Lines changed: 0 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -72,35 +72,6 @@ function Counter() {
72
72
}
73
73
```
74
74
75
-
> **Optimizing `useComputed` performance**
76
-
>
77
-
> The `useComputed` hook follows the convention of keeping closures fresh. By default, the callback function passed to `useComputed` will re-run on every component render to ensure it always has access to the latest values from the component's scope. However, if the computed value doesn't change, updates won't propagate to dependent nodes in the signal graph.
78
-
>
79
-
> For expensive computations, you can optimize performance by memoizing the callback with `useCallback`:
>// Memoize the callback to avoid re-running expensive calculations
89
-
>constexpensiveComputation=useCallback(() => {
90
-
>let result =count.value;
91
-
>for (let i =0; i <10000000; i++) {
92
-
> result +=1;
93
-
> }
94
-
>return result;
95
-
>// Empty deps means callback never changes, alternatively add count here so that if the identity of the signal changes this re-runs
96
-
> }, []);
97
-
>
98
-
>constcomputed=useComputed(expensiveComputation);
99
-
>
100
-
>return<div>Result: {computed}</div>;
101
-
> }
102
-
>```
103
-
104
75
### Rendering optimizations
105
76
106
77
The Preact adapter ships with several optimizations it can apply out of the box to skip virtual-dom rendering entirely. If you pass a signal directly into JSX, it will bind directly to the DOM `Text` node that is created and update that whenever the signal changes.
Copy file name to clipboardExpand all lines: packages/react/README.md
-28Lines changed: 0 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -103,34 +103,6 @@ function Counter() {
103
103
}
104
104
```
105
105
106
-
> **Optimizing `useComputed` performance**
107
-
>
108
-
> The `useComputed` hook follows the convention of keeping closures fresh. By default, the callback function passed to `useComputed` will re-run on every component render to ensure it always has access to the latest values from the component's scope. However, if the computed value doesn't change, updates won't propagate to dependent nodes in the signal graph.
109
-
>
110
-
> For expensive computations, you can optimize performance by memoizing the callback with `useCallback`:
>// Memoize the callback to avoid re-running expensive calculations
120
-
>constexpensiveComputation=useCallback(() => {
121
-
>for (let i =0; i <10000000; i++) {
122
-
> result +=1;
123
-
> }
124
-
>return result;
125
-
>// Empty deps means callback never changes, alternatively add count here so that if the identity of the signal changes this re-runs
126
-
> }, []);
127
-
>
128
-
>constcomputed=useComputed(expensiveComputation);
129
-
>
130
-
>return<div>Result: {computed.value}</div>;
131
-
> }
132
-
>```
133
-
134
106
### Using signals with React's SSR APIs
135
107
136
108
Components rendered using SSR APIs (e.g. `renderToString`) in a server environment (i.e. an environment without a global `window` object) will not track signals used during render. Components generally don't rerender when using SSR APIs so tracking signal usage is useless since changing these signals can't trigger a rerender.
0 commit comments