Skip to content

Commit 9653882

Browse files
add React 19 support (#1048)
1 parent 3683e57 commit 9653882

File tree

10 files changed

+1399
-491
lines changed

10 files changed

+1399
-491
lines changed

.changeset/poor-avocados-march.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@obosbbl/grunnmuren-icons-react': minor
3+
'@obosbbl/grunnmuren-react': minor
4+
---
5+
6+
add React 19 as allowed peerDep

form-demo/app/uncontrolled/page.tsx

+24-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
11
'use client';
2-
import { Form, TextField } from '@obosbbl/grunnmuren-react';
3-
import { useFormState } from 'react-dom';
2+
import { Button, Form, TextField } from '@obosbbl/grunnmuren-react';
3+
import { type FormEvent, startTransition, useActionState } from 'react';
44

55
import { submitForm } from './submit-action';
6-
import SubmitButton from './submit-button';
76

87
export default function () {
9-
const [{ errors }, formAction] = useFormState(submitForm, { errors: {} });
8+
const [{ errors }, formAction, isPending] = useActionState(submitForm, {
9+
errors: {},
10+
});
11+
12+
// cannot use action directly on the form submit, because it resets the form
13+
// which means our validation messages aren't displayed...
14+
// another workaround for this is here https://www.robinwieruch.de/react-server-action-reset-form/
15+
const handleSubmit = (event: FormEvent<HTMLFormElement>) => {
16+
event.preventDefault();
17+
startTransition(() => {
18+
formAction(new FormData(event.currentTarget));
19+
});
20+
};
1021

1122
return (
12-
<Form action={formAction} validationErrors={errors} className="space-y-4">
23+
<Form
24+
onSubmit={handleSubmit}
25+
validationErrors={errors}
26+
className="space-y-4"
27+
>
1328
<p>
1429
This is an uncontrolled form that uses zod to validate the form data on
1530
the server side in a React server action.
@@ -26,7 +41,10 @@ export default function () {
2641
</>
2742
}
2843
/>
29-
<SubmitButton>Save</SubmitButton>
44+
45+
<Button isPending={isPending} type="submit">
46+
Save
47+
</Button>
3048
</Form>
3149
);
3250
}

form-demo/app/uncontrolled/submit-action.tsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@ const schema = z.object({
66
email: z.string().email().endsWith('.no'),
77
});
88

9-
export async function submitForm(prevState: unknown, formData: FormData) {
9+
type SubmitFormResult = {
10+
errors: Record<string, string[]>;
11+
};
12+
13+
export async function submitForm(
14+
prevState: SubmitFormResult,
15+
formData: FormData,
16+
): Promise<SubmitFormResult> {
1017
const result = schema.safeParse(Object.fromEntries(formData));
1118

1219
// Simulate a delay

form-demo/app/uncontrolled/submit-button.tsx

-9
This file was deleted.

form-demo/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"dependencies": {
1313
"@obosbbl/grunnmuren-react": "workspace:*",
14-
"next": "14.2.16",
14+
"next": "15.1.0",
1515
"zod": "3.23.8"
1616
},
1717
"devDependencies": {

form-demo/tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
{
1717
"name": "next"
1818
}
19-
]
19+
],
20+
"target": "ES2017"
2021
},
2122
"include": ["next-env.d.ts", ".next/types/**/*.ts", "**/*.ts", "**/*.tsx"],
2223
"exclude": ["node_modules"]

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
"@storybook/test": "8.4.7",
3434
"@storybook/test-runner": "0.20.1",
3535
"@types/bun": "1.1.13",
36-
"@types/react": "18.3.12",
37-
"@types/react-dom": "18.3.1",
36+
"@types/react": "19.0.1",
37+
"@types/react-dom": "19.0.2",
3838
"autoprefixer": "10.4.20",
3939
"bunchee": "6.0.3",
4040
"fontaine": "0.5.0",
@@ -44,8 +44,8 @@
4444
"prettier": "3.2.5",
4545
"prettier-plugin-packagejson": "2.5.0",
4646
"prettier-plugin-tailwindcss": "0.5.14",
47-
"react": "18.3.1",
48-
"react-dom": "18.3.1",
47+
"react": "19.0.0",
48+
"react-dom": "19.0.0",
4949
"storybook": "8.4.7",
5050
"tailwindcss": "3.4.15",
5151
"typescript": "5.6.3"

packages/icons-react/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@
2828
"fs-extra": "11.2.0"
2929
},
3030
"peerDependencies": {
31-
"react": "^18"
31+
"react": "^18 || ^19"
3232
}
3333
}

packages/react/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@
2929
"react-aria-components": "^1.3.1"
3030
},
3131
"peerDependencies": {
32-
"react": "^18"
32+
"react": "^18 || ^19"
3333
}
3434
}

0 commit comments

Comments
 (0)