Skip to content

Commit 4406c2d

Browse files
committed
Fix page
1 parent 2f6556b commit 4406c2d

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

src/content/learn/updating-objects-in-state.md

+30-8
Original file line numberDiff line numberDiff line change
@@ -674,12 +674,11 @@ The `draft` provided by Immer is a special type of object, called a [Proxy](http
674674

675675
To 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+
683682
2. Then replace `import { useState } from 'react'` with `import { useImmer } from 'use-immer'`
684683

685684
Here is the above example converted to Immer:
@@ -1288,6 +1287,24 @@ body { height: 280px; }
12881287
select { 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

Comments
 (0)