Skip to content

Commit

Permalink
upgrade examples and packages to react 18 (#1718)
Browse files Browse the repository at this point in the history
* add react 18 support

* upgrade examples and packages to react 18

* fix unit tests for react@18

* upgrade react-testing-library

* fix antd tests

* update unit tests for react@18

* disable hoist

* update package-lock

* fix react-hook-form and react-table dependencies

* refactor: disable lerna bootstrap hoist

* fix: react@18 "children" type build issues

* fix: add "react-query" dependency for @pankod/refine-cloud package

* fix: add "@mui/icons-material" dependency for finefoods mui example

* fix: unit tests

* fix: react@18 build issues

* chore: update peerDependencies

* build: enable hoist mode

* refactor: update all dependencies to react@18

* fix: hoist finefoods mui example

* refactor: upgrade typescript to 4.7.4

* fix: react@18 issues on finefoods ant design example

* chore: update package-lock

* fix: axios version

* fix: react@18 compability

* fix: finefoods mui react@18 issues

* refactor: unit tests compability react@18

* refactor: react@18 compatibility of core package's unit tests
Co-authored-by: Ali Emir Şen <[email protected]>

* refactor: react@18 compatibility of antd package's unit tests

* refactor: react@18 compatibility of mui package's unit tests

* refactor: react@18 compatibility of react-hook-form example

* refactor: react@18 compatibility of refine-react-hook-form-use-steps-form-example example

* refactor: react@18 compatibility of refine-realworld-example

* refactor: react@18 compatibility of react-table example

* refactor: react@18 compatibility of refine-headless-tutorial-example

* style: reorder classNames on refine-headless-tutorial-example

* refactor: react@18 compatibility of refine-headless-tutorial-example

* refactor: react@18 compatibility of refine-ecommerce-example

* fix: react@18 children prop issue

* fix: multiple children on refine-email-subscriptions example

* fix: multiple children on refine-invoice-generator example

* fix: react@18 children prop issue

* fix: react-hook-form & mui react@18 compability

* docs: fix defaultValue for create form

* fix: mui storybook react@18 compability

* fix: add additional timeout for react-table test

* chore: add changeset
  • Loading branch information
omeraplak authored Jul 29, 2022
1 parent 9b80864 commit b38620d
Show file tree
Hide file tree
Showing 331 changed files with 3,179 additions and 2,878 deletions.
21 changes: 21 additions & 0 deletions .changeset/orange-bottles-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
"@pankod/refine-antd": minor
"@pankod/refine-antd-audit-log": minor
"@pankod/refine-cloud": minor
"@pankod/refine-core": minor
"@pankod/refine-demo-sidebar": minor
"@pankod/refine-hasura": minor
"@pankod/refine-kbar": minor
"@pankod/refine-mui": minor
"@pankod/refine-nextjs-router": minor
"@pankod/refine-nhost": minor
"@pankod/refine-react-hook-form": minor
"@pankod/refine-react-location": minor
"@pankod/refine-react-router-v6": minor
"@pankod/refine-react-table": minor
"@pankod/refine-sdk": minor
"@pankod/refine-strapi": minor
"@pankod/refine-strapi-v4": minor
---

Add React@18 support 🚀
3 changes: 2 additions & 1 deletion documentation/blog/2022-02-14-refine-ecommerce-blog.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,10 @@ We created our collections in the previous Strapi Multitenancy guide. Now we wil
The Layout we've created now will only show the **refine** logo. In the following steps, we will edit our Layout.

```tsx title="components/Layout.tsx"
import { LayoutProps } from "@pankod/refine-core";
import { Box, Container, Flex, Image } from "@chakra-ui/react";

export const Layout: React.FC = ({ children }) => {
export const Layout: React.FC<LayoutProps> = ({ children }) => {
return (
<Box
display={"flex"}
Expand Down
8 changes: 5 additions & 3 deletions documentation/blog/2022-03-01-refine-invoice-genarator-p2.md
Original file line number Diff line number Diff line change
Expand Up @@ -848,9 +848,11 @@ export const PdfLayout: React.FC<PdfProps> = ({ record }) => {
<div className="pdf-body">
<div id="grid"></div>
<p className="signature">
Signature: ________________ <br />
<br />
Date: {record?.date}
<>
Signature: ________________ <br />
<br />
Date: {record?.date}
</>
</p>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ The React Hook Form library has been integrated with **refine** ([`@pankod/refin
First, we'll create PostCreate page to create new records.

```tsx title="src/pages/posts/create"
import { HttpError } from "@pankod/refine-core";
import {
Box,
TextField,
Expand All @@ -399,7 +400,7 @@ import {
} from "@pankod/refine-mui";
import { useForm, Controller } from "@pankod/refine-react-hook-form";

import { ICategory } from "interfaces";
import { IPost, ICategory } from "interfaces";

export const PostCreate: React.FC = () => {
const {
Expand All @@ -408,7 +409,7 @@ export const PostCreate: React.FC = () => {
register,
control,
formState: { errors },
} = useForm();
} = useForm<IPost, HttpError, IPost & { category: ICategory }>();

const { autocompleteProps } = useAutocomplete<ICategory>({
resource: "categories",
Expand Down Expand Up @@ -550,6 +551,7 @@ Try it on the browser and see if you can create new posts from scratch.
We'll start by creating a new `<PostEdit>` page responsible for editing a existed single record:

```tsx title="src/pages/posts/edit.tsx"
import { HttpError } from "@pankod/refine-core";
import { Controller, useForm } from "@pankod/refine-react-hook-form";
import {
Edit,
Expand All @@ -559,7 +561,7 @@ import {
useAutocomplete,
} from "@pankod/refine-mui";

import { ICategory } from "interfaces";
import { IPost, ICategory } from "interfaces";

export const PostEdit: React.FC = () => {
const {
Expand All @@ -568,7 +570,9 @@ export const PostEdit: React.FC = () => {
register,
control,
formState: { errors },
} = useForm({ refineCoreProps: { metaData: { populate: ["category"] } } });
} = useForm<IPost, HttpError, IPost & { category: ICategory }>({
refineCoreProps: { metaData: { populate: ["category"] } },
});

const { autocompleteProps } = useAutocomplete<ICategory>({
resource: "categories",
Expand Down Expand Up @@ -600,7 +604,7 @@ export const PostEdit: React.FC = () => {
control={control}
name="category"
rules={{ required: "Category is required" }}
defaultValue=""
defaultValue={null as any}
render={({ field }) => (
<Autocomplete
{...autocompleteProps}
Expand Down
6 changes: 4 additions & 2 deletions documentation/docs/core/hooks/ui/useMenu.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ We will show you how to use `useMenu` to create a simple menu for your refine ap
Create a `<Layout />` component inside `src/components/layout.tsx` with the following code;

```tsx title="src/components/layout.tsx"
import { LayoutProps } from "@pankod/refine-core";
import { useMenu, useNavigation, useRouterContext, useRefineContext } from "@pankod/refine-core";

export const Layout: React.FC = ({ children }) => {
export const Layout: React.FC<LayoutProps> = ({ children }) => {
const { menuItems, selectedKey } = useMenu();
const { hasDashboard } = useRefineContext();
const { Link } = useRouterContext();
Expand Down Expand Up @@ -200,9 +201,10 @@ export const App: React.FC = () => {
Now you can update your `<Layout/>` to support multi level rendering with following code:

```tsx title="src/components/Layout.tsx"
import { LayoutProps } from "@pankod/refine-core";
import { useMenu, useNavigation, useRouterContext } from "@pankod/refine-core";

export const Layout: React.FC = ({ children }) => {
export const Layout: React.FC<LayoutProps> = ({ children }) => {
const { menuItems, selectedKey } = useMenu();
const { Link } = useRouterContext();

Expand Down
4 changes: 2 additions & 2 deletions documentation/docs/core/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -417,12 +417,12 @@ We will create a **Layout** component to handle the rendering of the **Page** co
Create a new folder named _"components"_ under _"/src"_ and create a new file named _"Layout.tsx"_ with the following code:

```tsx title="components/Layout.tsx"
import { useMenu, useNavigation } from "@pankod/refine-core";
import { useMenu, useNavigation, LayoutProps } from "@pankod/refine-core";
import routerProvider from "@pankod/refine-react-router-v6";

const { Link } = routerProvider;

export const Layout: React.FC = ({ children }) => {
export const Layout: React.FC<LayoutProps> = ({ children }) => {
const { menuItems } = useMenu();
const { push } = useNavigation();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ export const PostList: React.FC = () => {

### Properties

| Property | Description | Type | Default |
| -------------------- | ------------------------------------------ | -------------------------------------------------------------------- | ---------------------------------------------------------- |
| value | Field value | `unknown` | |
| Property | Description | Type | Default |
| -------------------- | -------------------------------------------- | -------------------------------------------------------------------- | ---------------------------------------------------------- |
| value | Field value | `unknown` | |
| valueLabelTrue | If there is a value, this is the text to use | `string` | `"true"` |
| valueLabelFalse | If there no value, this is the text to use | `string` | `"false"` |
| trueIcon | If there is a value, this is the icon to use | `React.FC` \| `object` | [`<CheckOutlined />`](https://ant.design/components/icon/) |
| falseIcon | If there no value, this is the icon to use. | `React.FC` \| `object` | [`<CloseOutlined />`](https://ant.design/components/icon/) |
| AbstractTooltipProps | Ant Design `Tooltip` properties | [`AbstractTooltipProps`](https://ant.design/components/tooltip/#API) | |
| trueIcon | If there is a value, this is the icon to use | `React.ReactNode` | [`<CheckOutlined />`](https://ant.design/components/icon/) |
| falseIcon | If there no value, this is the icon to use. | `React.ReactNode` | [`<CloseOutlined />`](https://ant.design/components/icon/) |
| AbstractTooltipProps | Ant Design `Tooltip` properties | [`AbstractTooltipProps`](https://ant.design/components/tooltip/#API) | |
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ export const ColorModeContext = createContext<ColorModeContextType>(
{} as ColorModeContextType,
);

export const ColorModeContextProvider: React.FC = ({ children }) => {
export const ColorModeContextProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
const colorModeFromLocalStorage = localStorage.getItem("colorMode");
const isSystemPreferenceDark = window?.matchMedia(
"(prefers-color-scheme: dark)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ We'll demonstrate how to get data at `/categories` endpoint from `https://api.fa
```

```tsx title="pages/posts/create.tsx"
import { HttpError } from "@pankod/refine-core";
import {
Create,
Box,
Expand All @@ -50,7 +51,7 @@ export const PostCreate = () => {
register,
control,
formState: { errors },
} = useForm();
} = useForm<IPost, HttpError, IPost & { category: ICategory }>();

// highlight-start
const { autocompleteProps } = useAutocomplete<ICategory>({
Expand Down Expand Up @@ -109,6 +110,12 @@ interface ICategory {
id: number;
title: string;
}

export interface IPost {
id: number;
category: { id: number };
}

```

The use of `useAutocomplete` with [`useForm`](/packages/react-hook-form/useForm.md) is demonstrated in the code above. You can use the `useAutocomplete` hook independently of the `useForm`hook.
Expand Down
17 changes: 9 additions & 8 deletions documentation/docs/ui-frameworks/mui/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -1032,16 +1032,17 @@ The React Hook Form library has been integrated with **refine** ([`@pankod/refin
Let's start by creating a new `<PostEdit>` page responsible for `editing` a single record:

```tsx title="src/pages/posts/edit.tsx"
import { Controller, useForm } from "@pankod/refine-react-hook-form";
import { HttpError } from "@pankod/refine-core";
import {
Edit,
Box,
TextField,
Autocomplete,
useAutocomplete,
} from "@pankod/refine-mui";
import { Controller, useForm } from "@pankod/refine-react-hook-form";

import { ICategory } from "interfaces";
import { ICategory, IPost } from "interfaces";

export const PostEdit: React.FC = () => {
const {
Expand All @@ -1050,7 +1051,7 @@ export const PostEdit: React.FC = () => {
register,
control,
formState: { errors },
} = useForm();
} = useForm<IPost, HttpError, IPost & { category: ICategory }>();

const { autocompleteProps } = useAutocomplete<ICategory>({
resource: "categories",
Expand Down Expand Up @@ -1082,7 +1083,7 @@ export const PostEdit: React.FC = () => {
control={control}
name="status"
rules={{ required: "Status is required" }}
defaultValue=""
defaultValue={null as any}
render={({ field }) => (
<Autocomplete
{...field}
Expand All @@ -1108,7 +1109,7 @@ export const PostEdit: React.FC = () => {
control={control}
name="category"
rules={{ required: "Category is required" }}
defaultValue=""
defaultValue={null as any}
render={({ field }) => (
<Autocomplete
{...autocompleteProps}
Expand Down Expand Up @@ -1351,6 +1352,7 @@ Creating a record in **refine** follows a similar flow as `editing` records.
First, we'll create a `<PostCreate>` page:

```tsx title="src/pages/posts/create.tsx"
import { HttpError } from "@pankod/refine-core";
import {
Box,
TextField,
Expand All @@ -1360,7 +1362,7 @@ import {
} from "@pankod/refine-mui";
import { useForm, Controller } from "@pankod/refine-react-hook-form";

import { ICategory } from "interfaces";
import { IPost, ICategory } from "interfaces";

export const PostCreate: React.FC = () => {
const {
Expand All @@ -1369,7 +1371,7 @@ export const PostCreate: React.FC = () => {
register,
control,
formState: { errors },
} = useForm();
} = useForm<IPost, HttpError, IPost & { category: ICategory }>();

const { autocompleteProps } = useAutocomplete<ICategory>({
resource: "categories",
Expand Down Expand Up @@ -1398,7 +1400,6 @@ export const PostCreate: React.FC = () => {
control={control}
name="status"
rules={{ required: "Status is required" }}
defaultValue=""
render={({ field }) => (
<Autocomplete
{...field}
Expand Down
10 changes: 5 additions & 5 deletions examples/ably/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
"@pankod/refine-react-router-v6": "^3.29.0",
"@pankod/refine-simple-rest": "^3.27.0",
"@types/node": "^12.20.11",
"@types/react": "^17.0.4",
"@types/react-dom": "^17.0.4",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-markdown": "^6.0.1",
"react-mde": "^11.1.0",
"react-scripts": "^5.0.0",
"typescript": "^4.4.3"
"typescript": "^4.7.4"
},
"scripts": {
"start": "DISABLE_ESLINT_PLUGIN=true react-scripts start",
Expand Down
10 changes: 5 additions & 5 deletions examples/accessControl/casbin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
"@pankod/refine-react-router-v6": "^3.29.0",
"@pankod/refine-simple-rest": "^3.27.0",
"@types/node": "^12.20.11",
"@types/react": "^17.0.4",
"@types/react-dom": "^17.0.4",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"casbin": "^5.15.2",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-markdown": "^6.0.1",
"react-mde": "^11.1.0",
"react-scripts": "^4.0.0",
"typescript": "^4.4.3"
"typescript": "^4.7.4"
},
"scripts": {
"start": "DISABLE_ESLINT_PLUGIN=true react-scripts start",
Expand Down
10 changes: 5 additions & 5 deletions examples/accessControl/cerbos/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
"@pankod/refine-react-router-v6": "^3.29.0",
"@pankod/refine-simple-rest": "^3.27.0",
"@types/node": "^12.20.11",
"@types/react": "^17.0.4",
"@types/react-dom": "^17.0.4",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-markdown": "^6.0.1",
"react-mde": "^11.1.0",
"react-scripts": "^5.0.0",
"typescript": "^4.4.3"
"typescript": "^4.7.4"
},
"scripts": {
"start": "DISABLE_ESLINT_PLUGIN=true react-scripts start",
Expand Down
10 changes: 5 additions & 5 deletions examples/antdAuditLog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
"@pankod/refine-sdk": "^0.0.25",
"@pankod/refine-simple-rest": "^3.27.0",
"@types/node": "^12.20.11",
"@types/react": "^17.0.4",
"@types/react-dom": "^17.0.4",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-markdown": "^6.0.1",
"react-mde": "^11.1.0",
"react-scripts": "^5.0.0",
"typescript": "^4.4.3"
"typescript": "^4.7.4"
},
"scripts": {
"start": "DISABLE_ESLINT_PLUGIN=true react-scripts start",
Expand Down
10 changes: 5 additions & 5 deletions examples/auditLogProvider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
"@pankod/refine-react-router-v6": "^3.29.0",
"@pankod/refine-simple-rest": "^3.27.0",
"@pankod/refine-react-hook-form": "^3.29.0",
"react": "^17.0.2",
"react-dom": "^17.0.2"
"react": "^18.0.0",
"react-dom": "^18.0.0"
},
"devDependencies": {
"@types/react": "^17.0.4",
"@types/react-dom": "^17.0.4",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"@vitejs/plugin-react": "^1.0.7",
"typescript": "^4.4.3",
"typescript": "^4.7.4",
"vite": "^2.8.0",
"vite-plugin-cdn-import": "^0.3.5"
},
Expand Down
1 change: 1 addition & 0 deletions examples/auditLogProvider/src/components/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React from "react";
type ModalPropsType = {
isOpen: boolean;
onClose: () => void;
children: React.ReactNode;
};

export const Modal: React.FC<ModalPropsType> = ({
Expand Down
Loading

0 comments on commit b38620d

Please sign in to comment.