Skip to content

Commit 505db59

Browse files
authored
fix(antd/next): fix useRecord return function (#3227)
1 parent 8c9ab06 commit 505db59

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

packages/antd/src/array-base/index.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ const ArrayBaseContext = createContext<IArrayBaseContext>(null)
7474

7575
const ItemContext = createContext<IArrayBaseItemProps>(null)
7676

77+
const takeRecord = (val: any) => (typeof val === 'function' ? val() : val)
78+
7779
const useArray = () => {
7880
return useContext(ArrayBaseContext)
7981
}
@@ -85,7 +87,7 @@ const useIndex = (index?: number) => {
8587

8688
const useRecord = (record?: number) => {
8789
const ctx = useContext(ItemContext)
88-
return ctx ? ctx.record : record
90+
return takeRecord(ctx ? ctx.record : record)
8991
}
9092

9193
const getSchemaDefaultValue = (schema: Schema) => {
@@ -123,9 +125,7 @@ ArrayBase.Item = ({ children, ...props }) => {
123125
<ItemContext.Provider value={props}>
124126
<RecordScope
125127
getIndex={() => props.index}
126-
getRecord={() =>
127-
typeof props.record === 'function' ? props.record() : props.record
128-
}
128+
getRecord={() => takeRecord(props.record)}
129129
>
130130
{children}
131131
</RecordScope>

packages/next/src/array-base/index.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ const ArrayBaseContext = createContext<IArrayBaseContext>(null)
7070

7171
const ItemContext = createContext<IArrayBaseItemProps>(null)
7272

73+
const takeRecord = (val: any) => (typeof val === 'function' ? val() : val)
74+
7375
const useArray = () => {
7476
return useContext(ArrayBaseContext)
7577
}
@@ -81,7 +83,7 @@ const useIndex = (index?: number) => {
8183

8284
const useRecord = (record?: number) => {
8385
const ctx = useContext(ItemContext)
84-
return ctx ? ctx.record : record
86+
return takeRecord(ctx ? ctx.record : record)
8587
}
8688

8789
const getSchemaDefaultValue = (schema: Schema) => {
@@ -119,9 +121,7 @@ ArrayBase.Item = ({ children, ...props }) => {
119121
<ItemContext.Provider value={props}>
120122
<RecordScope
121123
getIndex={() => props.index}
122-
getRecord={() =>
123-
typeof props.record === 'function' ? props.record() : props.record
124-
}
124+
getRecord={() => takeRecord(props.record)}
125125
>
126126
{children}
127127
</RecordScope>

0 commit comments

Comments
 (0)