Skip to content

Commit 7c878bf

Browse files
committed
quelques modif sur les exemples
1 parent a114be6 commit 7c878bf

7 files changed

Lines changed: 10 additions & 80 deletions

File tree

src/examples/use-context-1/ExampleUseContext102.tsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,6 @@ const Consumer = () => {
3030

3131
return (
3232
<ul>
33-
<li>
34-
<ActionButton
35-
label="Do nothing state-wise"
36-
onClick={() => {
37-
/* NOOP */
38-
}}
39-
/>
40-
</li>
4133
<li>
4234
<ActionButton
4335
label="Increment"

src/examples/use-effect-1/ExampleUseEffect102.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,7 @@ const ExampleUseState106 = () => {
7777
const [str, setStr] = React.useState<{ str: string }>({ str: "" });
7878

7979
return (
80-
<SubComponent
81-
value={counter}
82-
setValue={setCounter}
83-
otherValue={str}
84-
setOtherValue={setStr}
85-
/>
80+
<SubComponent value={counter} setValue={setCounter} otherValue={str} setOtherValue={setStr} />
8681
);
8782
};
8883

src/examples/use-effect-1/ExampleUseEffect103.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const SubComponent = ({
2828
log("use effect");
2929
if (shouldSetSuperState) setOtherValue(otherValue);
3030
else setOtherState(otherValue);
31-
}, [otherValue, setOtherState, setOtherValue, shouldSetSuperState]);
31+
}, [otherValue, setOtherState, setOtherValue, shouldSetSuperState, log]);
3232

3333
return (
3434
<>

src/examples/use-state-1/ExampleUseState102.tsx

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,16 @@
11
import React from "react";
22
import ActionButton from "../../commons/ActionButton";
3-
import cloneDeep from "lodash.clonedeep";
43

54
const ExampleUseState102 = () => {
6-
const [state, setState] = React.useState<{ value: { data: number } }>({
5+
const initial = {
76
value: { data: 0 }
8-
});
7+
};
8+
const [state, setState] = React.useState<{ value: { data: number } }>(initial);
99

1010
return (
1111
<>
1212
<pre>{JSON.stringify(state, null, 2)}</pre>
1313
<ul>
14-
<li>
15-
<ActionButton
16-
label="Do nothing state-wise"
17-
onClick={() => {
18-
/* NOOP */
19-
}}
20-
/>
21-
</li>
2214
<li>
2315
<ActionButton
2416
label="Increment"
@@ -31,15 +23,7 @@ const ExampleUseState102 = () => {
3123
<ActionButton
3224
label="Reset to 0"
3325
onClick={() => {
34-
setState({ value: { data: 0 } });
35-
}}
36-
/>
37-
</li>
38-
<li>
39-
<ActionButton
40-
label="Re-apply state copy"
41-
onClick={() => {
42-
setState(cloneDeep(state));
26+
setState(initial);
4327
}}
4428
/>
4529
</li>

src/examples/use-state-1/ExampleUseState103.tsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,6 @@ const ExampleUseState103 = () => {
1010
<>
1111
<pre>{JSON.stringify({ state }, null, 2)}</pre>
1212
<ul>
13-
<li>
14-
<ActionButton
15-
label="Do nothing state-wise"
16-
onClick={() => {
17-
/* NOOP */
18-
}}
19-
/>
20-
</li>
2113
<li>
2214
<ActionButton
2315
label="Increment"

src/examples/use-state-1/ExampleUseState104.tsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,6 @@ const ExampleUseState104 = () => {
1111
<>
1212
<pre>{JSON.stringify({ state, stateF }, null, 2)}</pre>
1313
<ul>
14-
<li>
15-
<ActionButton
16-
label="Do nothing state-wise"
17-
onClick={() => {
18-
/* NOOP */
19-
}}
20-
/>
21-
</li>
2214
<li>
2315
<ActionButton
2416
label={"Change function basic"}

src/examples/use-state-1/ExampleUseState105.tsx

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,46 +5,21 @@ import { useLog } from "../../commons/ExampleBloc";
55
const ExampleUseState105 = () => {
66
const log = useLog();
77

8-
const [numberState, setNumberState] = React.useState<number>(0);
9-
const [stringState, setStringState] = React.useState<string>("");
8+
const [render, setRender] = React.useState<boolean>(false);
109
const [objectState, setObjectState] = React.useState<{ insideVal: string }>({
1110
insideVal: ""
1211
});
1312

1413
return (
1514
<>
16-
<pre>
17-
{JSON.stringify({ numberState, stringState, objectState }, null, 2)}
18-
</pre>
15+
<pre>{JSON.stringify({ render, objectState }, null, 2)}</pre>
1916

2017
<ul>
2118
<li>
2219
<ActionButton
23-
label="Update numberState"
20+
label="render"
2421
onClick={() => {
25-
const s = Number.parseFloat(prompt("Value?") || "");
26-
log("Will update", s);
27-
setNumberState(s);
28-
}}
29-
/>
30-
</li>
31-
<li>
32-
<ActionButton
33-
label="Update stringState"
34-
onClick={() => {
35-
const s = prompt("Value?") || "";
36-
log("Will update", s);
37-
setStringState(s);
38-
}}
39-
/>
40-
</li>
41-
<li>
42-
<ActionButton
43-
label="Update objectState"
44-
onClick={() => {
45-
const s = prompt("Value?") || "";
46-
log("Will update", s);
47-
setObjectState({ insideVal: s });
22+
setRender(b => !b);
4823
}}
4924
/>
5025
</li>

0 commit comments

Comments
 (0)