Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(Space): solve space circular dependency issue #42811

Merged
merged 2 commits into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/space/Item.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { SpaceContext } from '.';
import { SpaceContext } from './context';

export interface ItemProps {
className: string;
Expand Down
10 changes: 10 additions & 0 deletions components/space/context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';

export const SpaceContext = React.createContext({
latestIndex: 0,
horizontalSize: 0,
verticalSize: 0,
supportFlexGap: false,
});

export const SpaceContextProvider = SpaceContext.Provider;
10 changes: 3 additions & 7 deletions components/space/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@ import type { SizeType } from '../config-provider/SizeContext';
import Compact from './Compact';
import Item from './Item';

import { SpaceContextProvider } from './context';
import useStyle from './style';

export const SpaceContext = React.createContext({
latestIndex: 0,
horizontalSize: 0,
verticalSize: 0,
supportFlexGap: false,
});
export type { SpaceContext } from './context';

export type SpaceSize = SizeType | number;

Expand Down Expand Up @@ -159,7 +155,7 @@ const Space = React.forwardRef<HTMLDivElement, SpaceProps>((props, ref) => {
}}
{...otherProps}
>
<SpaceContext.Provider value={spaceContext}>{nodes}</SpaceContext.Provider>
<SpaceContextProvider value={spaceContext}>{nodes}</SpaceContextProvider>
</div>,
);
});
Expand Down