@@ -674,12 +674,11 @@ The `draft` provided by Immer is a special type of object, called a [Proxy](http
674
674
675
675
To try Immer:
676
676
677
- 1 . <TabTerminalBlock
678
- tabs={[
679
- { label: 'npm', value: 'npm', content: 'npm install use-immer' },
680
- { label: 'Bun', value: 'bun', content: 'bun add use-immer' }
681
- ] }
682
- />
677
+ 1 . Install the package:
678
+ ``` bash
679
+ npm install use-immer
680
+ ```
681
+
683
682
2 . Then replace ` import { useState } from 'react' ` with ` import { useImmer } from 'use-immer' `
684
683
685
684
Here is the above example converted to Immer:
@@ -1288,6 +1287,24 @@ body { height: 280px; }
1288
1287
select { margin-bottom : 10px ; }
1289
1288
```
1290
1289
1290
+ ``` json package.json
1291
+ {
1292
+ "dependencies" : {
1293
+ "immer" : " 1.7.3" ,
1294
+ "react" : " latest" ,
1295
+ "react-dom" : " latest" ,
1296
+ "react-scripts" : " latest" ,
1297
+ "use-immer" : " 0.5.1"
1298
+ },
1299
+ "scripts" : {
1300
+ "start" : " react-scripts start" ,
1301
+ "build" : " react-scripts build" ,
1302
+ "test" : " react-scripts test --env=jsdom" ,
1303
+ "eject" : " react-scripts eject"
1304
+ }
1305
+ }
1306
+ ```
1307
+
1291
1308
</Sandpack >
1292
1309
1293
1310
</Solution >
@@ -1316,8 +1333,13 @@ export default function Canvas() {
1316
1333
});
1317
1334
1318
1335
function handleMove (dx , dy ) {
1319
- shape .position .x += dx;
1320
- shape .position .y += dy;
1336
+ setShape ({
1337
+ ... shape,
1338
+ position: {
1339
+ x: shape .position .x + dx,
1340
+ y: shape .position .y + dy,
1341
+ }
1342
+ });
1321
1343
}
1322
1344
1323
1345
function handleColorChange (e ) {
0 commit comments