Skip to content

Commit

Permalink
fix(antd/next): fix array base record ref data is not newest in expre…
Browse files Browse the repository at this point in the history
…ssion (#3358)
  • Loading branch information
janryWang authored Aug 29, 2022
1 parent dd0d8be commit 35cd143
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
14 changes: 7 additions & 7 deletions packages/antd/src/array-base/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export interface IArrayBaseContext {

export interface IArrayBaseItemProps {
index: number
record: any
record: ((index: number) => Record<string, any>) | Record<string, any>
}

export type ArrayBaseMixins = {
Expand Down Expand Up @@ -77,7 +77,8 @@ const ArrayBaseContext = createContext<IArrayBaseContext>(null)

const ItemContext = createContext<IArrayBaseItemProps>(null)

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

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

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

const getSchemaDefaultValue = (schema: Schema) => {
Expand Down Expand Up @@ -124,12 +125,11 @@ export const ArrayBase: ComposedArrayBase = (props) => {
}

ArrayBase.Item = ({ children, ...props }) => {
const index = props.index
const record = takeRecord(props.record, props.index)
return (
<ItemContext.Provider value={props}>
<RecordScope
getIndex={() => props.index}
getRecord={() => takeRecord(props.record)}
>
<RecordScope getIndex={() => index} getRecord={() => record}>
{children}
</RecordScope>
</ItemContext.Provider>
Expand Down
14 changes: 7 additions & 7 deletions packages/next/src/array-base/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export interface IArrayBaseContext {

export interface IArrayBaseItemProps {
index: number
record: any
record: ((index: number) => Record<string, any>) | Record<string, any>
}

export type ArrayBaseMixins = {
Expand Down Expand Up @@ -77,7 +77,8 @@ const ArrayBaseContext = createContext<IArrayBaseContext>(null)

const ItemContext = createContext<IArrayBaseItemProps>(null)

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

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

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

const getSchemaDefaultValue = (schema: Schema) => {
Expand Down Expand Up @@ -124,12 +125,11 @@ export const ArrayBase: ComposedArrayBase = (props) => {
}

ArrayBase.Item = ({ children, ...props }) => {
const index = props.index
const record = takeRecord(props.record, props.index)
return (
<ItemContext.Provider value={props}>
<RecordScope
getIndex={() => props.index}
getRecord={() => takeRecord(props.record)}
>
<RecordScope getIndex={() => index} getRecord={() => record}>
{children}
</RecordScope>
</ItemContext.Provider>
Expand Down

0 comments on commit 35cd143

Please sign in to comment.