demo: update demo type { children: React.ReactNode } => React.PropsWithChildren (#48771)

* demo: update demo type React.ReactNode => React.PropsWithChildren

* fix: fix
This commit is contained in:
lijianan 2024-05-06 12:04:27 +08:00 committed by GitHub
parent 313d534f2b
commit 8b1f79c1f5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 13 additions and 17 deletions

View File

@ -88,7 +88,7 @@ describe('Button', () => {
});
it('renders Chinese characters correctly in HOC', () => {
const Text = ({ children }: { children: React.ReactNode }) => <span>{children}</span>;
const Text: React.FC<React.PropsWithChildren> = ({ children }) => <span>{children}</span>;
const { container, rerender } = render(
<Button>
<Text></Text>

View File

@ -6,14 +6,16 @@ const MyFormItemContext = React.createContext<(string | number)[]>([]);
interface MyFormItemGroupProps {
prefix: string | number | (string | number)[];
children: React.ReactNode;
}
function toArr(str: string | number | (string | number)[]): (string | number)[] {
return Array.isArray(str) ? str : [str];
}
const MyFormItemGroup = ({ prefix, children }: MyFormItemGroupProps) => {
const MyFormItemGroup: React.FC<React.PropsWithChildren<MyFormItemGroupProps>> = ({
prefix,
children,
}) => {
const prefixPath = React.useContext(MyFormItemContext);
const concatPath = React.useMemo(() => [...prefixPath, ...toArr(prefix)], [prefixPath, prefix]);

View File

@ -1,7 +1,7 @@
import React from 'react';
import { Col, Divider, Row } from 'antd';
const DemoBox: React.FC<{ children: React.ReactNode; value: number }> = (props) => (
const DemoBox: React.FC<React.PropsWithChildren<{ value: number }>> = (props) => (
<p className={`height-${props.value}`}>{props.children}</p>
);

View File

@ -31,13 +31,12 @@ const EditableRow: React.FC<EditableRowProps> = ({ index, ...props }) => {
interface EditableCellProps {
title: React.ReactNode;
editable: boolean;
children: React.ReactNode;
dataIndex: keyof Item;
record: Item;
handleSave: (record: Item) => void;
}
const EditableCell: React.FC<EditableCellProps> = ({
const EditableCell: React.FC<React.PropsWithChildren<EditableCellProps>> = ({
title,
editable,
children,

View File

@ -25,10 +25,9 @@ interface EditableCellProps extends React.HTMLAttributes<HTMLElement> {
inputType: 'number' | 'text';
record: Item;
index: number;
children: React.ReactNode;
}
const EditableCell: React.FC<EditableCellProps> = ({
const EditableCell: React.FC<React.PropsWithChildren<EditableCellProps>> = ({
editing,
dataIndex,
title,

View File

@ -1,7 +1,7 @@
import React from 'react';
import { Button, Checkbox, Input, InputNumber, Select, Space, Tooltip } from 'antd';
const WrapperTooltip: React.FC<{ children?: React.ReactNode }> = (props) => (
const WrapperTooltip: React.FC<React.PropsWithChildren> = (props) => (
<Tooltip title="Thanks for using antd. Have a nice day!" {...props} />
);

View File

@ -80,7 +80,7 @@ const useButtonStyle = () => {
}))();
};
function GeekProvider(props: { children?: React.ReactNode }) {
function GeekProvider(props: React.PropsWithChildren) {
const { styles } = useButtonStyle();
return <ConfigProvider button={{ className: styles.btn }}>{props.children}</ConfigProvider>;
@ -92,7 +92,7 @@ function GeekProvider(props: { children?: React.ReactNode }) {
It's also easy to extend for scenarios that need to inherit `className`:
```tsx
function GeekProvider(props: { children?: React.ReactNode }) {
function GeekProvider(props: React.PropsWithChildren) {
const { button } = React.useContext(ConfigProvider.ConfigContext);
const { styles } = useButtonStyle();

View File

@ -5,11 +5,7 @@ import { TriggerMockContext } from '../../../shared/demoTestContext';
let OriginPortal = jest.requireActual('rc-util/lib/Portal');
OriginPortal = OriginPortal.default ?? OriginPortal;
interface MockPortalProps {
children?: React.ReactNode
}
class MockPortal extends React.Component<MockPortalProps> {
class MockPortal extends React.Component<React.PropsWithChildren> {
container: boolean | undefined;
static contextType = TriggerMockContext;
@ -32,7 +28,7 @@ class MockPortal extends React.Component<MockPortalProps> {
}
}
const CustomPortal = React.forwardRef<PortalRef, PortalProps | MockPortalProps>((props, ref) => {
const CustomPortal = React.forwardRef<PortalRef, PortalProps | React.PropsWithChildren>((props, ref) => {
const context = React.useContext(TriggerMockContext);
if (context?.mock === false) {
return <OriginPortal {...props} ref={ref} />;