@@ -674,12 +674,11 @@ The `draft` provided by Immer is a special type of object, called a [Proxy](http
674674
675675To try Immer:
676676
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+
6836822 . Then replace ` import { useState } from 'react' ` with ` import { useImmer } from 'use-immer' `
684683
685684Here is the above example converted to Immer:
@@ -1288,6 +1287,24 @@ body { height: 280px; }
12881287select { margin-bottom : 10px ; }
12891288```
12901289
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+
12911308</Sandpack >
12921309
12931310</Solution >
@@ -1316,8 +1333,13 @@ export default function Canvas() {
13161333 });
13171334
13181335 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+ });
13211343 }
13221344
13231345 function handleColorChange (e ) {
0 commit comments