Skip to content

Commit 2bb9349

Browse files
committed
fix(reloadState): stabilize render edge cases
1 parent bbcc26e commit 2bb9349

20 files changed

Lines changed: 1884 additions & 2123 deletions

File tree

examples/simple-form/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"@astrojs/react": "^3.6.0",
1818
"@types/react": "^18.3.3",
1919
"@types/react-dom": "^18.3.0",
20-
"astro": "^4.7.0",
20+
"astro": "^4.16.19",
2121
"bootstrap": "^5.3.2",
2222
"react": "^18.3.1",
2323
"react-dom": "^18.3.1",
Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
---
22
import { BButton, Bind, BindForm } from "@astro-utils/forms/forms.js";
33
4-
const bind = Bind();
5-
const { session, forms } = Astro.locals;
4+
interface Props {
5+
incParentCounter: () => void;
6+
debugParam?: string;
7+
}
8+
9+
const { incParentCounter, debugParam } = Astro.props;
10+
const bind = Bind({counter: 0, debugParam});
11+
const { forms } = Astro.locals;
612
713
async function onSubmit(){
8-
session.counter ??= 0;
9-
session.counter++;
14+
bind.counter++;
15+
incParentCounter();
1016
forms.reloadState();
1117
}
1218
1319
---
1420
<BindForm {bind}>
15-
<p>Counter of sub-state: {session.counter}</p>
21+
<p>Counter of sub-state: {bind.counter}</p>
1622
<BButton onClick={onSubmit}>Button From Sub-State</BButton>
1723
</BindForm>
Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,37 @@
11
---
2-
import { BButton, Bind, BindForm, BInput } from "@astro-utils/forms/forms.js";
2+
import { BButton, Bind, BindForm, BInput } from '@astro-utils/forms/forms.js';
33
import { Button } from 'reactstrap';
4-
import Layout from "../layouts/Layout.astro";
5-
import SubState from "../components/SubState.astro";
4+
import Layout from '../layouts/Layout.astro';
5+
import SubState from '../components/SubState.astro';
66
7-
const { session } = Astro.locals;
8-
const bind = Bind();
7+
const bind = Bind({counter: 0});
98
109
async function increaseCounter() {
11-
session.counter ??= 0
12-
session.counter++;
10+
bind.counter++;
1311
}
14-
1512
---
16-
<Layout title="counter">
13+
14+
<Layout title='counter'>
1715
<p>
1816
The inner state reload the parent state, so the parent state will show the new date from the child. <br />
1917
In this example when you click on the inner-state counter, it will reload the parent counter as well.
2018
</p>
2119
<BindForm {bind}>
22-
<BInput name="name" />
23-
<BButton as={Button} onClick={increaseCounter}>++</BButton>
24-
{session.counter}
20+
<BindForm>
21+
<BInput name='name' />
22+
<BButton as={Button} onClick={increaseCounter}>++</BButton>
23+
{bind.counter}
24+
25+
<p>Sub-state1</p>
26+
{[<SubState incParentCounter={increaseCounter} debugParam='1' />, <SubState incParentCounter={increaseCounter} debugParam='2' />]}
27+
28+
</BindForm>
29+
30+
<BindForm>
31+
<BInput name='name' />
32+
<p>Sub-state2</p>
33+
{[<SubState incParentCounter={increaseCounter} debugParam='3' />, <SubState incParentCounter={increaseCounter} debugParam='4' />]}
2534

26-
<p>Sub-state</p>
27-
<SubState />
35+
</BindForm>
2836
</BindForm>
29-
</Layout>
37+
</Layout>

0 commit comments

Comments
 (0)