Skip to content

Commit 7f1f52a

Browse files
authored
Merge pull request #6952 from refinedev/feat/update-hook-return-types
feat(core): update hook return types
2 parents 0dd971a + 4517211 commit 7f1f52a

File tree

649 files changed

+10685
-6439
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

649 files changed

+10685
-6439
lines changed

documentation/blog/2021-10-6-migrating-react-admin-application-to-refine.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ export const CampaignsList: React.FC<IResourceComponentsProps> = () => {
130130
onChange: handleSelectChange,
131131
};
132132

133-
const { mutate, isLoading } = useDeleteMany<ICampaign>();
133+
const {
134+
mutate,
135+
mutation: { isPending },
136+
} = useDeleteMany<ICampaign>();
134137

135138
const deleteSelectedItems = () => {
136139
mutate(
@@ -156,7 +159,7 @@ export const CampaignsList: React.FC<IResourceComponentsProps> = () => {
156159
<Button
157160
type="text"
158161
onClick={() => deleteSelectedItems()}
159-
loading={isLoading}
162+
loading={isPending}
160163
icon={<Icons.DeleteOutlined style={{ color: "green" }} />}
161164
>
162165
Delete

documentation/blog/2021-11-12-issue-tracker-refine.md

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ import {
585585
import { Filter } from "../task";
586586

587587
export const TaskList = () => {
588-
const { tableProps, searchFormProps } = useTable<
588+
const { result, searchFormProps } = useTable<
589589
ITask,
590590
HttpError,
591591
ITaskFilterVariables
@@ -654,28 +654,27 @@ export const TaskList = () => {
654654
},
655655
});
656656

657-
const labelIds = tableProps?.dataSource?.map((item) => item.label) ?? [];
658-
const priorityIds =
659-
tableProps?.dataSource?.map((item) => item.priority) ?? [];
660-
const assignedIds = tableProps?.dataSource?.map((item) => item.users) ?? [];
661-
const statusIds = tableProps?.dataSource?.map((item) => item.status) ?? [];
657+
const labelIds = result?.data?.map((item) => item.label) ?? [];
658+
const priorityIds = result?.data?.map((item) => item.priority) ?? [];
659+
const assignedIds = result?.data?.map((item) => item.users) ?? [];
660+
const statusIds = result?.data?.map((item) => item.status) ?? [];
662661

663-
const { data: labels } = useMany<ILabel>({
662+
const { result: labels } = useMany<ILabel>({
664663
resource: "label",
665664
ids: labelIds,
666665
});
667666

668-
const { data: priority } = useMany<IPriority>({
667+
const { result: priority } = useMany<IPriority>({
669668
resource: "priority",
670669
ids: priorityIds,
671670
});
672671

673-
const { data: assigned } = useMany<IAuthUser>({
672+
const { result: assigned } = useMany<IAuthUser>({
674673
resource: "users",
675674
ids: assignedIds,
676675
});
677676

678-
const { data: status } = useMany<IStatus>({
677+
const { result: status } = useMany<IStatus>({
679678
resource: "status",
680679
ids: statusIds,
681680
});
@@ -1064,31 +1063,30 @@ import { ITask, ILabel, IPriority, IStatus, IAuthUser } from "interfaces";
10641063
const { Title, Text } = Typography;
10651064

10661065
export const TaskShow: React.FC = () => {
1067-
const { query } = useShow<ITask>();
1068-
const { data, isLoading } = query;
1069-
const record = data?.data;
1066+
const { result: record, query } = useShow<ITask>();
1067+
const { isLoading } = query;
10701068

1071-
const { data: assigned } = useOne<IAuthUser>({
1069+
const { result: assigned } = useOne<IAuthUser>({
10721070
resource: "users",
10731071
id: record?.users || "",
10741072
});
10751073

1076-
const { data: label } = useOne<ILabel>({
1074+
const { result: label } = useOne<ILabel>({
10771075
resource: "label",
10781076
id: record?.label || "",
10791077
});
10801078

1081-
const { data: priority } = useOne<IPriority>({
1079+
const { result: priority } = useOne<IPriority>({
10821080
resource: "priority",
10831081
id: record?.priority || "",
10841082
});
10851083

1086-
const { data: status } = useOne<IStatus>({
1084+
const { result: status } = useOne<IStatus>({
10871085
resource: "status",
10881086
id: record?.status || "",
10891087
});
10901088

1091-
console.log(status?.data);
1089+
console.log(status);
10921090

10931091
return (
10941092
<Show isLoading={isLoading}>
@@ -1100,19 +1098,19 @@ export const TaskShow: React.FC = () => {
11001098

11011099
<Title level={5}>Assigned To:</Title>
11021100
<Text>
1103-
<Tag>{assigned?.data?.email ?? "-"}</Tag>
1101+
<Tag>{assigned?.email ?? "-"}</Tag>
11041102
</Text>
11051103

11061104
<Title level={5}>Label:</Title>
11071105
<Text>
1108-
<Tag>{label?.data?.title ?? "-"}</Tag>
1106+
<Tag>{label?.title ?? "-"}</Tag>
11091107
</Text>
11101108

11111109
<Title level={5}>Priority:</Title>
1112-
<Text>{priority?.data?.title ?? "-"}</Text>
1110+
<Text>{priority?.title ?? "-"}</Text>
11131111

11141112
<Title level={5}>Status:</Title>
1115-
<Text>{status?.data?.title ?? "-"}</Text>
1113+
<Text>{status?.title ?? "-"}</Text>
11161114

11171115
<Title level={5}>Start Date:</Title>
11181116
<DateField format="DD/MM/YYYY" value={record?.start_time ?? "-"} />
@@ -1181,27 +1179,27 @@ export const Dashboard = () => {
11811179
resource: "tasks",
11821180
});
11831181

1184-
const labelIds = taskList.data?.data.map((item) => item.label) ?? [];
1185-
const priorityIds = taskList.data?.data.map((item) => item.priority) ?? [];
1186-
const assignedIds = taskList.data?.data.map((item) => item.users) ?? [];
1187-
const statusIds = taskList.data?.data.map((item) => item.status) ?? [];
1182+
const labelIds = taskList.result?.data.map((item) => item.label) ?? [];
1183+
const priorityIds = taskList.result?.data.map((item) => item.priority) ?? [];
1184+
const assignedIds = taskList.result?.data.map((item) => item.users) ?? [];
1185+
const statusIds = taskList.result?.data.map((item) => item.status) ?? [];
11881186

1189-
const { data: labels } = useMany<ILabel>({
1187+
const { result: labels } = useMany<ILabel>({
11901188
resource: "label",
11911189
ids: labelIds || [],
11921190
});
11931191

1194-
const { data: priority } = useMany<IPriority>({
1192+
const { result: priority } = useMany<IPriority>({
11951193
resource: "priority",
11961194
ids: priorityIds || [],
11971195
});
11981196

1199-
const { data: assigned } = useMany<IAuthUser>({
1197+
const { result: assigned } = useMany<IAuthUser>({
12001198
resource: "users",
12011199
ids: assignedIds || [],
12021200
});
12031201

1204-
const { data: status } = useMany<IStatus>({
1202+
const { result: status } = useMany<IStatus>({
12051203
resource: "status",
12061204
ids: statusIds || [],
12071205
});

documentation/blog/2022-02-21-react-antd-admin.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -702,11 +702,10 @@ import { IPost, ICategory } from "interfaces";
702702

703703
export const PostList = () => {
704704
const translate = useTranslate();
705-
const { tableProps } = useTable<IPost>();
705+
const { result } = useTable<IPost>();
706706

707-
const categoryIds =
708-
tableProps?.dataSource?.map((item) => item.category.id) ?? [];
709-
const { data, isLoading } = useMany<ICategory>({
707+
const categoryIds = result?.data?.map((item) => item.category.id) ?? [];
708+
const { result, isLoading } = useMany<ICategory>({
710709
resource: "categories",
711710
ids: categoryIds,
712711
queryOptions: {
@@ -746,7 +745,7 @@ export const PostList = () => {
746745

747746
return (
748747
<TextField
749-
value={data?.data.find((item) => item.id === value)?.title}
748+
value={result?.data.find((item) => item.id === value)?.title}
750749
/>
751750
);
752751
}}

documentation/blog/2022-03-22-refine-with-react95.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,9 +1054,7 @@ export const PostList = () => {
10541054
getState,
10551055
setPageIndex,
10561056
setPageSize,
1057-
refineCore: {
1058-
tableQuery: { isLoading },
1059-
},
1057+
refineCore: { result },
10601058
} = useTable<IPost>({
10611059
columns,
10621060
refineCoreProps: {

documentation/blog/2022-09-22-refine-supabase-auth.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,10 +571,12 @@ import { Table } from "react-daisyui";
571571
const columns = ["ID", "Name", "ISO Code", "Local Name", "Continent"];
572572

573573
export const Countries = () => {
574-
const { data: countries } = useList({
574+
const { result } = useList({
575575
resource: "countries",
576576
pagination: { mode: "off" },
577577
});
578+
const countries = result?.data;
579+
578580
return (
579581
<div className="overflow-x-auto">
580582
<Table color="primary" className="w-full">

documentation/blog/2023-01-17-airtable-crud-app.md

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Before the existence of **Refine**, building CRUD applications and data-intensiv
1616

1717
Steps we'll cover:
1818

19+
- [Introduction](#introduction)
1920
- [Why Use Refine?](#why-use-refine)
2021
- [What is Airtable?](#what-is-airtable)
2122
- [Setup Airtable](#setup-airtable)
@@ -29,6 +30,8 @@ Steps we'll cover:
2930
- [Editing post record](#editing-post-record)
3031
- [Deleting post record](#deleting-post-record)
3132
- [Adding Pagination](#adding-pagination)
33+
- [Conclusion](#conclusion)
34+
- [Live CodeSandbox Example](#live-codesandbox-example)
3235

3336
## Why Use Refine?
3437

@@ -683,14 +686,12 @@ export const PostList: React.FC = () => {
683686
getHeaderGroups,
684687
getRowModel,
685688
setOptions,
686-
refineCore: {
687-
tableQuery: { data: tableData },
688-
},
689+
refineCore: { result },
689690
} = useTable<IPost>({ columns });
690691

691-
const categoryIds = tableData?.data?.map((item) => item.category?.[0]) ?? [];
692+
const categoryIds = result?.data?.map((item) => item.category?.[0]) ?? [];
692693

693-
const { data: categoriesData } = useMany<ICategory>({
694+
const { result: categoriesData } = useMany<ICategory>({
694695
resource: "category",
695696
ids: categoryIds,
696697
queryOptions: {
@@ -801,13 +802,11 @@ import { useSelect, useShow } from "@refinedev/core";
801802
import { IPost } from "../../interfaces/post";
802803

803804
export const PostShow: React.FC = () => {
804-
const { query } = useShow<IPost>();
805-
const { data } = query;
806-
const record = data?.data;
805+
const { result } = useShow<IPost>();
807806

808807
const { options } = useSelect({
809808
resource: "category",
810-
defaultValue: query?.data?.data?.category?.[0],
809+
defaultValue: result?.category?.[0],
811810
optionLabel: "name",
812811
optionValue: "id",
813812
});
@@ -1525,9 +1524,7 @@ export const PostList: React.FC = () => {
15251524
getHeaderGroups,
15261525
getRowModel,
15271526
setOptions,
1528-
refineCore: {
1529-
tableQuery: { data: tableData },
1530-
},
1527+
refineCore: { result },
15311528
getState,
15321529
setPageIndex,
15331530
getCanPreviousPage,
@@ -1539,9 +1536,9 @@ export const PostList: React.FC = () => {
15391536
} = useTable<IPost>({ columns });
15401537
// highlight-end
15411538

1542-
const categoryIds = tableData?.data?.map((item) => item.category?.[0]) ?? [];
1539+
const categoryIds = result?.data?.map((item) => item.category?.[0]) ?? [];
15431540

1544-
const { data: categoriesData } = useMany<ICategory>({
1541+
const { result: categoriesData } = useMany<ICategory>({
15451542
resource: "category",
15461543
ids: categoryIds,
15471544
queryOptions: {

documentation/blog/2023-02-14-refine-pixels-1.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ The underlying architecture involves any presentational component passed to `<Re
120120
An example hook usage looks like this:
121121

122122
```tsx title="Inside a UI component"
123-
const { data } = useList<Canvas>({
123+
const { result } = useList<Canvas>({
124124
resource: "canvases",
125125
pagination: {
126126
mode: "off",

documentation/blog/2023-02-17-refine-pixels-4.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ export const DisplayCanvas: React.FC<DisplayCanvasProps> = ({
354354
canvas: { id },
355355
children,
356356
}) => {
357-
const { data } = useList<Pixel>({
357+
const { result } = useList<Pixel>({
358358
resource: "pixels",
359359
liveMode: "auto",
360360
meta: {

documentation/blog/2023-02-23-refine-strapi-mantine.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ export const PostList: React.FC = () => {
201201
const {
202202
getHeaderGroups,
203203
getRowModel,
204-
refineCore: { setCurrent, pageCount, current },
204+
refineCore: { setCurrentPage, pageCount, currentPage },
205205
} = useTable({
206206
columns,
207207
});
@@ -249,8 +249,8 @@ export const PostList: React.FC = () => {
249249
<Pagination
250250
position="right"
251251
total={pageCount}
252-
page={current}
253-
onChange={setCurrent}
252+
page={currentPage}
253+
onChange={setCurrentPage}
254254
/>
255255
</List>
256256
);
@@ -492,7 +492,7 @@ import { useTable } from "@refinedev/react-table";
492492
const {
493493
getHeaderGroups,
494494
getRowModel,
495-
refineCore: { setCurrent, pageCount, current },
495+
refineCore: { setCurrentPage, pageCount, currentPage },
496496
} = useTable({
497497
columns,
498498
//highlight-start

0 commit comments

Comments
 (0)