Skip to content

Commit

Permalink
fix(antd/next): fix useRecord return function (#3227)
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang authored Jun 26, 2022
1 parent 8c9ab06 commit 505db59
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions packages/antd/src/array-base/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ const ArrayBaseContext = createContext<IArrayBaseContext>(null)

const ItemContext = createContext<IArrayBaseItemProps>(null)

const takeRecord = (val: any) => (typeof val === 'function' ? val() : val)

const useArray = () => {
return useContext(ArrayBaseContext)
}
Expand All @@ -85,7 +87,7 @@ const useIndex = (index?: number) => {

const useRecord = (record?: number) => {
const ctx = useContext(ItemContext)
return ctx ? ctx.record : record
return takeRecord(ctx ? ctx.record : record)
}

const getSchemaDefaultValue = (schema: Schema) => {
Expand Down Expand Up @@ -123,9 +125,7 @@ ArrayBase.Item = ({ children, ...props }) => {
<ItemContext.Provider value={props}>
<RecordScope
getIndex={() => props.index}
getRecord={() =>
typeof props.record === 'function' ? props.record() : props.record
}
getRecord={() => takeRecord(props.record)}
>
{children}
</RecordScope>
Expand Down
8 changes: 4 additions & 4 deletions packages/next/src/array-base/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ const ArrayBaseContext = createContext<IArrayBaseContext>(null)

const ItemContext = createContext<IArrayBaseItemProps>(null)

const takeRecord = (val: any) => (typeof val === 'function' ? val() : val)

const useArray = () => {
return useContext(ArrayBaseContext)
}
Expand All @@ -81,7 +83,7 @@ const useIndex = (index?: number) => {

const useRecord = (record?: number) => {
const ctx = useContext(ItemContext)
return ctx ? ctx.record : record
return takeRecord(ctx ? ctx.record : record)
}

const getSchemaDefaultValue = (schema: Schema) => {
Expand Down Expand Up @@ -119,9 +121,7 @@ ArrayBase.Item = ({ children, ...props }) => {
<ItemContext.Provider value={props}>
<RecordScope
getIndex={() => props.index}
getRecord={() =>
typeof props.record === 'function' ? props.record() : props.record
}
getRecord={() => takeRecord(props.record)}
>
{children}
</RecordScope>
Expand Down

0 comments on commit 505db59

Please sign in to comment.