Skip to content

Commit 9eff6b8

Browse files
committed
chore: cleanup React.FC prop types (#655)
1 parent c069dff commit 9eff6b8

17 files changed

+77
-44
lines changed

.changeset/serious-garlics-refuse.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@craftjs/layers': patch
3+
'@craftjs/utils': patch
4+
'@craftjs/core': patch
5+
---
6+
7+
Cleanup React.FC prop types

packages/core/src/editor/Editor.tsx

+11-6
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ import { useEditorStore } from './store';
88
import { Events } from '../events';
99
import { Options } from '../interfaces';
1010

11+
type EditorProps = Partial<Options> & {
12+
children?: React.ReactNode;
13+
};
14+
1115
/**
1216
* A React Component that provides the Editor context
1317
*/
14-
export const Editor: React.FC<React.PropsWithChildren<Partial<Options>>> = ({
15-
children,
16-
...options
17-
}) => {
18+
export const Editor = ({ children, ...options }: EditorProps) => {
1819
// we do not want to warn the user if no resolver was supplied
1920
if (options.resolver !== undefined) {
2021
invariant(
@@ -101,9 +102,13 @@ export const Editor: React.FC<React.PropsWithChildren<Partial<Options>>> = ({
101102
);
102103
}, [context]);
103104

104-
return context ? (
105+
if (!context) {
106+
return null;
107+
}
108+
109+
return (
105110
<EditorContext.Provider value={context}>
106111
<Events>{children}</Events>
107112
</EditorContext.Provider>
108-
) : null;
113+
);
109114
};

packages/core/src/events/Events.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ type EventsProps = {
99
children?: React.ReactNode;
1010
};
1111

12-
export const Events: React.FC<EventsProps> = ({ children }) => {
12+
export const Events = ({ children }: EventsProps) => {
1313
const store = useContext(EditorContext);
1414

1515
const handler = useMemo(() => store.query.getOptions().handlers(store), [

packages/core/src/nodes/NodeContext.tsx

+8-4
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@ export type NodeContextType = {
99

1010
export const NodeContext = React.createContext<NodeContextType>(null);
1111

12-
export type NodeProviderProps = Omit<NodeContextType, 'connectors'>;
12+
export type NodeProviderProps = Omit<NodeContextType, 'connectors'> & {
13+
children?: React.ReactNode;
14+
};
1315

14-
export const NodeProvider: React.FC<React.PropsWithChildren<
15-
NodeProviderProps
16-
>> = ({ id, related = false, children }) => {
16+
export const NodeProvider = ({
17+
id,
18+
related = false,
19+
children,
20+
}: NodeProviderProps) => {
1721
return (
1822
<NodeContext.Provider value={{ id, related }}>
1923
{children}

packages/core/src/nodes/NodeElement.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ export type NodeElementProps = {
1010
render?: React.ReactElement;
1111
};
1212

13-
export const NodeElement: React.FC<React.PropsWithChildren<
14-
NodeElementProps
15-
>> = ({ id, render }) => {
13+
export const NodeElement = ({ id, render }: NodeElementProps) => {
1614
return (
1715
<NodeProvider id={id}>
1816
<RenderNodeToElement render={render} />

packages/core/src/render/Frame.tsx

+2-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { SerializedNodes } from '../interfaces';
66
import { NodeElement } from '../nodes/NodeElement';
77

88
export type FrameProps = {
9+
children?: React.ReactNode;
910
json?: string;
1011
data?: string | SerializedNodes;
1112
};
@@ -26,11 +27,7 @@ const RenderRootNode = () => {
2627
/**
2728
* A React Component that defines the editable area
2829
*/
29-
export const Frame: React.FC<React.PropsWithChildren<FrameProps>> = ({
30-
children,
31-
json,
32-
data,
33-
}) => {
30+
export const Frame = ({ children, json, data }: FrameProps) => {
3431
const { actions, query } = useInternalEditor();
3532

3633
if (!!json) {

packages/core/src/render/RenderNode.tsx

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ import { DefaultRender } from './DefaultRender';
55
import { useInternalEditor } from '../editor/useInternalEditor';
66
import { useInternalNode } from '../nodes/useInternalNode';
77

8-
type RenderNodeToElementType = {
8+
type RenderNodeToElementProps = {
99
render?: React.ReactElement;
10+
children?: React.ReactNode;
1011
};
11-
export const RenderNodeToElement: React.FC<React.PropsWithChildren<
12-
RenderNodeToElementType
13-
>> = ({ render }) => {
12+
export const RenderNodeToElement = ({ render }: RenderNodeToElementProps) => {
1413
const { hidden } = useInternalNode((node) => ({
1514
hidden: node.data.hidden,
1615
}));

packages/core/src/render/RenderPlaceholder.tsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ import React from 'react';
33
import { useEditor } from '../hooks';
44
import { Indicator } from '../interfaces';
55

6-
export type Placeholder = {
6+
export type RenderPlaceholderProps = {
77
placeholder: Indicator;
88
suggestedStyles: any;
99
};
1010

11-
export const RenderPlaceholder: React.FC<React.PropsWithChildren<
12-
Placeholder
13-
>> = ({ placeholder, suggestedStyles }) => {
11+
export const RenderPlaceholder = ({
12+
placeholder,
13+
suggestedStyles,
14+
}: RenderPlaceholderProps) => {
1415
const { indicator } = useEditor((state) => ({
1516
indicator: state.options.indicator,
1617
}));

packages/layers/src/events/RenderLayerIndicator.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ import React, { useMemo } from 'react';
44

55
import { useLayerManager } from '../manager/useLayerManager';
66

7-
export const RenderLayerIndicator: React.FC<any> = ({ children }) => {
7+
type RenderLayerIndicatorProps = {
8+
children?: React.ReactNode;
9+
};
10+
11+
export const RenderLayerIndicator = ({
12+
children,
13+
}: RenderLayerIndicatorProps) => {
814
const { layers, events } = useLayerManager((state) => state);
915
const { query } = useEditor((state) => ({ enabled: state.options.enabled }));
1016
const { indicator: indicatorStyles } = query.getOptions();

packages/layers/src/index.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ export {
1111
EditableLayerName,
1212
} from './layers';
1313

14-
export const Layers: React.FC<Partial<LayerOptions>> = ({ ...options }) => {
14+
type LayersProps = Partial<LayerOptions>;
15+
16+
export const Layers = ({ ...options }: LayersProps) => {
1517
return (
1618
<LayerManagerProvider options={options}>
1719
<LayerContextProvider id={ROOT_NODE} depth={0} />

packages/layers/src/layers/DefaultLayer/DefaultLayer.tsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ const LayerChildren = styled.div<{ hasCanvases: boolean }>`
4444
: ''}
4545
`;
4646

47-
export const DefaultLayer: React.FC<{ children?: React.ReactNode }> = ({
48-
children,
49-
}) => {
47+
export type DefaultLayerProps = {
48+
children?: React.ReactNode;
49+
};
50+
51+
export const DefaultLayer = ({ children }: DefaultLayerProps) => {
5052
const {
5153
id,
5254
expanded,

packages/layers/src/layers/DefaultLayer/DefaultLayerHeader.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ const TopLevelIndicator = styled.div`
9191
}
9292
`;
9393

94-
export const DefaultLayerHeader: React.FC = () => {
94+
export const DefaultLayerHeader = () => {
9595
const {
9696
id,
9797
depth,

packages/layers/src/layers/LayerContextProvider.tsx

+6-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ import { LayerNode } from './LayerNode';
88
import { useLayerEventHandler } from '../events/LayerEventContext';
99
import { LayerManagerContext } from '../manager';
1010

11-
export const LayerContextProvider: React.FC<Omit<
12-
LayerContextType,
13-
'connectors'
14-
>> = ({ id, depth }) => {
11+
export type LayerContextProviderProps = Omit<LayerContextType, 'connectors'>;
12+
13+
export const LayerContextProvider = ({
14+
id,
15+
depth,
16+
}: LayerContextProviderProps) => {
1517
const handlers = useLayerEventHandler();
1618

1719
const { store } = useContext(LayerManagerContext);

packages/layers/src/layers/LayerIndicator.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { Indicator, useEditor } from '@craftjs/core';
22
import React from 'react';
33

4-
export type Placeholder = {
4+
export type LayerIndicatorProps = {
55
placeholder: Indicator;
66
suggestedStyles: any;
77
};
88

9-
export const LayerIndicator: React.FC<Placeholder> = ({
9+
export const LayerIndicator = ({
1010
placeholder,
1111
suggestedStyles,
12-
}) => {
12+
}: LayerIndicatorProps) => {
1313
const { indicator } = useEditor((state) => ({
1414
indicator: state.options.indicator,
1515
}));

packages/layers/src/layers/LayerNode.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { useLayer } from './useLayer';
66

77
import { useLayerManager } from '../manager/useLayerManager';
88

9-
export const LayerNode: React.FC = () => {
9+
export const LayerNode = () => {
1010
const { id, depth, children, expanded } = useLayer((layer) => ({
1111
expanded: layer.expanded,
1212
}));

packages/layers/src/manager/LayerManagerProvider.tsx

+7-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@ import { LayerEventContextProvider } from '../events';
88
import { LayerOptions } from '../interfaces';
99
import { DefaultLayer } from '../layers';
1010

11-
export const LayerManagerProvider: React.FC<{
11+
type LayerManagerProviderProps = {
1212
options: Partial<LayerOptions>;
1313
children?: React.ReactNode;
14-
}> = ({ children, options }) => {
14+
};
15+
16+
export const LayerManagerProvider = ({
17+
children,
18+
options,
19+
}: LayerManagerProviderProps) => {
1520
// TODO: fix type
1621
const store = useMethods(LayerMethods, {
1722
layers: {},

packages/utils/src/RenderIndicator.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import React from 'react';
22
import ReactDOM from 'react-dom';
33

4-
export const RenderIndicator: React.FC<any> = ({ style, parentDom }) => {
4+
type RenderIndicatorProps = {
5+
style: React.CSSProperties;
6+
parentDom?: HTMLElement;
7+
};
8+
9+
export const RenderIndicator = ({ style, parentDom }: RenderIndicatorProps) => {
510
const indicator = (
611
<div
712
style={{

0 commit comments

Comments
 (0)