Skip to content

Commit b8d0aee

Browse files
committed
fix: 使用时会报错找不到 React
因为打包时会把 jsx 内容用 React.createElement 包起来,用到的地方导入 React 完整包即可
1 parent 60438f7 commit b8d0aee

File tree

8 files changed

+24
-24
lines changed

8 files changed

+24
-24
lines changed

packages/components/src/draggable/Draggable.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
import type { DraggableProps, DraggableFC } from './draggable.types';
33
import { mergeReactDefaultProps, getClasses } from '@pkg/shared';
44
// import { useLocale } from '~/config-provider/useLocale';
5+
import React, { createElement, forwardRef } from 'react';
56
import { TransitionGroup } from '~/transition-group';
6-
import { createElement, forwardRef } from 'react';
77
import { getClassNames } from '@tool-pack/basic';
88
import { useDraggableChildren } from './hooks';
9-
import type { ReactElement } from 'react';
109

1110
export const cls = getClasses('draggable', ['ghost', 'item'], ['hidden']);
1211
const defaultProps = {
@@ -29,7 +28,7 @@ export const _Draggable = forwardRef<HTMLDivElement, DraggableProps>(
2928
const transitionProps = transition === true ? undefined : transition;
3029
return (
3130
<TransitionGroup {...transitionProps} className={className} tag={tag}>
32-
{children as ReactElement[]}
31+
{children as React.ReactElement[]}
3332
</TransitionGroup>
3433
);
3534
}

packages/components/src/draggable/DraggableGroup.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { createContext, ReactElement, useRef, FC } from 'react';
21
import type { DraggableGroupProps } from './draggable.types';
2+
import React, { createContext, useRef, FC } from 'react';
33
import { mergeReactDefaultProps } from '@pkg/shared';
44

55
const defaultProps = {
@@ -10,7 +10,7 @@ const defaultProps = {
1010
* 在 dragstart 里生产,在 dragenter 消费,在 drop | dragend 销毁
1111
*/
1212
export interface DraggableGroupContextProvider {
13-
readonly children: ReactElement;
13+
readonly children: React.ReactElement;
1414
cancel?: (id: symbol) => void;
1515
enter?: (id: symbol) => void;
1616
drop?: (id: symbol) => void;

packages/components/src/draggable/hooks/useDraggableChildren.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
useForceUpdate,
99
} from '@pkg/shared';
1010
import type { DOMAttributes, ReactElement, ReactNode, DragEvent } from 'react';
11-
import { cloneElement, useContext, Children, useRef } from 'react';
11+
import React, { cloneElement, useContext, useRef } from 'react';
1212
import { getClassNames, insertToArray } from '@tool-pack/basic';
1313
import type { DraggableProps } from '~/draggable';
1414
import { moveItem } from '../utils';
@@ -27,7 +27,7 @@ export function useDraggableChildren({
2727
const forceUpdate = useForceUpdate();
2828
const modifyChildrenRef = useFollowingRef(
2929
outerChildren,
30-
(v) => Children.map(v, (i) => i) || [],
30+
(v) => React.Children.map(v, (i) => i) || [],
3131
);
3232
const listRef = useFollowingRef(list, (v) => ({
3333
origin: v.slice(),

packages/components/src/loading/hooks/useLoading.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { LoadingProps } from '../loading.types';
22
import { createRoot } from 'react-dom/client';
3-
import { useEffect, useState } from 'react';
43
import { Loading } from '../Loading';
4+
import React from 'react';
55

66
/**
77
* 调用hook开启loading,无需挂靠render
@@ -15,9 +15,9 @@ export function useLoading(props: Partial<LoadingProps> = {}): {
1515
} {
1616
const { visible = true, ...rest } = props;
1717
// 可以通过外面传入的visible控制显隐
18-
const [_visible, setVisible] = useState(false);
18+
const [_visible, setVisible] = React.useState(false);
1919

20-
useEffect(() => {
20+
React.useEffect(() => {
2121
if (_visible) {
2222
const r = createRoot(document.createElement('div'));
2323
r.render(
@@ -36,7 +36,7 @@ export function useLoading(props: Partial<LoadingProps> = {}): {
3636
}
3737
}, [_visible]);
3838

39-
useEffect(() => {
39+
React.useEffect(() => {
4040
setVisible(visible);
4141
}, [visible]);
4242

packages/components/src/loading/showLoading.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { LoadingProps } from './loading.types';
22
import { createRoot, Root } from 'react-dom';
33
import { Loading } from './Loading';
4+
import React from 'react';
45

56
let root: undefined | Root;
67

@@ -15,7 +16,7 @@ export function showLoading(
1516
if (root) root.unmount();
1617

1718
const r = createRoot(document.createElement('div'));
18-
r.render(
19+
const l: React.ReactElement = (
1920
<Loading
2021
closeOnClick={true}
2122
visible={true}
@@ -24,7 +25,8 @@ export function showLoading(
2425
r.unmount();
2526
root = undefined;
2627
}}
27-
/>,
28+
/>
2829
);
30+
r.render(l);
2931
root = r;
3032
}

packages/components/src/message/useMessage.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { MessagePushOptions, MessageQueueRef } from './message.types';
2-
import { useCallback, useEffect, useMemo, useRef } from 'react';
2+
import React, { useCallback, useEffect, useMemo, useRef } from 'react';
33
import type { PartialPart } from '@tool-pack/types';
44
import { MessageQueue } from './MessageQueue';
55
import { nextTick } from '@tool-pack/basic';

packages/components/src/picker/components/picker.Col.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { debounceTime, fromEvent, timer, race, take, tap } from 'rxjs';
22
import { OptionValueType, getClasses } from '@pkg/shared';
33
import { getClassNames, emptyFn } from '@tool-pack/basic';
4+
import React, { useEffect, useRef } from 'react';
45
import type { PickerOption } from '~/picker';
5-
import { useEffect, useRef } from 'react';
66
import { Option } from '~/option';
77

88
interface Props {

packages/components/src/transition-group/hooks/useChildMap.tsx

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
import {
2-
isValidElement,
3-
cloneElement,
4-
useEffect,
5-
useState,
6-
Children,
7-
} from 'react';
81
import type {
92
FunctionComponentElement,
103
ReactElement,
@@ -16,6 +9,12 @@ import {
169
transitionCBAdapter,
1710
Transition,
1811
} from '~/transition';
12+
import React, {
13+
isValidElement,
14+
cloneElement,
15+
useEffect,
16+
useState,
17+
} from 'react';
1918
import type { ChildMapValue, ChildMap } from '../transition-group.types';
2019
import { useIsInitDep, forwardRefs } from '@pkg/shared';
2120

@@ -60,7 +59,7 @@ function createMap(
6059
const map: ChildMap = new Map();
6160

6261
// 如果没有手动添加key, Children.map会自动添加key,就算手动添加也会被 map 处理一遍,跟原来的不一样
63-
Children.map(children, (c) => c)?.forEach((child) => {
62+
React.Children.map(children, (c) => c)?.forEach((child) => {
6463
if (!isValidElement(child)) return;
6564
const key = child.key || '';
6665
if (!key) return;
@@ -78,7 +77,7 @@ function mergeChildMap(
7877
): ChildMap {
7978
const childMap: ChildMap = new Map();
8079
const map = new Map<Key, ReactElement>();
81-
Children.map(children, (c) => c)?.forEach(
80+
React.Children.map(children, (c) => c)?.forEach(
8281
(c) => isValidElement(c) && c.key && map.set(c.key, c),
8382
);
8483
let insertKeys: Key[] = [];

0 commit comments

Comments
 (0)