Skip to content

React 19 #1048

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/poor-avocados-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@obosbbl/grunnmuren-icons-react': minor
'@obosbbl/grunnmuren-react': minor
---

add React 19 as allowed peerDep
30 changes: 24 additions & 6 deletions form-demo/app/uncontrolled/page.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
'use client';
import { Form, TextField } from '@obosbbl/grunnmuren-react';
import { useFormState } from 'react-dom';
import { Button, Form, TextField } from '@obosbbl/grunnmuren-react';
import { type FormEvent, startTransition, useActionState } from 'react';

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

export default function () {
const [{ errors }, formAction] = useFormState(submitForm, { errors: {} });
const [{ errors }, formAction, isPending] = useActionState(submitForm, {
errors: {},
});

// cannot use action directly on the form submit, because it resets the form
// which means our validation messages aren't displayed...
// another workaround for this is here https://www.robinwieruch.de/react-server-action-reset-form/
const handleSubmit = (event: FormEvent<HTMLFormElement>) => {
event.preventDefault();
startTransition(() => {
formAction(new FormData(event.currentTarget));
});
};

return (
<Form action={formAction} validationErrors={errors} className="space-y-4">
<Form
onSubmit={handleSubmit}
validationErrors={errors}
className="space-y-4"
>
<p>
This is an uncontrolled form that uses zod to validate the form data on
the server side in a React server action.
Expand All @@ -26,7 +41,10 @@ export default function () {
</>
}
/>
<SubmitButton>Save</SubmitButton>

<Button isPending={isPending} type="submit">
Save
</Button>
</Form>
);
}
9 changes: 8 additions & 1 deletion form-demo/app/uncontrolled/submit-action.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ const schema = z.object({
email: z.string().email().endsWith('.no'),
});

export async function submitForm(prevState: unknown, formData: FormData) {
type SubmitFormResult = {
errors: Record<string, string[]>;
};

export async function submitForm(
prevState: SubmitFormResult,
formData: FormData,
): Promise<SubmitFormResult> {
const result = schema.safeParse(Object.fromEntries(formData));

// Simulate a delay
Expand Down
9 changes: 0 additions & 9 deletions form-demo/app/uncontrolled/submit-button.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion form-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"dependencies": {
"@obosbbl/grunnmuren-react": "workspace:*",
"next": "14.2.16",
"next": "15.1.0",
"zod": "3.23.8"
},
"devDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion form-demo/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
{
"name": "next"
}
]
],
"target": "ES2017"
},
"include": ["next-env.d.ts", ".next/types/**/*.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
"@storybook/test": "8.4.7",
"@storybook/test-runner": "0.20.1",
"@types/bun": "1.1.13",
"@types/react": "18.3.12",
"@types/react-dom": "18.3.1",
"@types/react": "19.0.1",
"@types/react-dom": "19.0.2",
"autoprefixer": "10.4.20",
"bunchee": "6.0.3",
"fontaine": "0.5.0",
Expand All @@ -44,8 +44,8 @@
"prettier": "3.2.5",
"prettier-plugin-packagejson": "2.5.0",
"prettier-plugin-tailwindcss": "0.5.14",
"react": "18.3.1",
"react-dom": "18.3.1",
"react": "19.0.0",
"react-dom": "19.0.0",
"storybook": "8.4.7",
"tailwindcss": "3.4.15",
"typescript": "5.6.3"
Expand Down
2 changes: 1 addition & 1 deletion packages/icons-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
"fs-extra": "11.2.0"
},
"peerDependencies": {
"react": "^18"
"react": "^18 || ^19"
}
}
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
"react-aria-components": "^1.3.1"
},
"peerDependencies": {
"react": "^18"
"react": "^18 || ^19"
}
}
Loading
Loading