Skip to content

Commit 74c5542

Browse files
committed
clean: remove redundant code. #50
1 parent 75e7066 commit 74c5542

File tree

2 files changed

+5
-15
lines changed

2 files changed

+5
-15
lines changed

core/src/switch.store.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { createContext, useContext, useReducer } from 'react';
1+
import React from 'react';
2+
import { useContext, useReducer } from 'react';
23

34
export type InitialState = {
45
[key: string]: React.ReactNode;
@@ -8,7 +9,7 @@ export type InitialState = {
89
};
910

1011
const initialState: InitialState = {};
11-
export const Context = createContext<InitialState>(initialState);
12+
export const Context = React.createContext<InitialState>(initialState);
1213

1314
const reducer = (state: InitialState, action: InitialState) => {
1415
action.active = action.active ?? {};
@@ -28,7 +29,7 @@ export function useSwitch() {
2829
}
2930

3031
type Dispatch = React.Dispatch<InitialState>;
31-
export const DispatchSwitch = createContext<Dispatch>(() => {});
32+
export const DispatchSwitch = React.createContext<Dispatch>(() => {});
3233
DispatchSwitch.displayName = 'OW.DispatchSwitch';
3334

3435
export function useSwitchDispatch() {

core/src/switch.tsx

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,13 @@
11
import { type FC, type PropsWithChildren } from 'react';
22
import { DispatchSwitch, Context, useSwitch, useSwitchStore } from './switch.store';
3-
import { Case, Default } from './case';
43

54
export * from './case';
65

76
export const Switch: FC<PropsWithChildren<{}>> = ({ children }) => {
87
const [state, dispatch] = useSwitch();
9-
const filteredChildren = [];
10-
const childs = Array.isArray(children) ? children : children ? [children] : null;
11-
if (childs) {
12-
for (let i = 0; i < childs.length; i++) {
13-
const child = childs[i];
14-
if (child && (child.type === Case || child.type === Default)) {
15-
filteredChildren.push(child);
16-
}
17-
}
18-
}
198
return (
209
<Context.Provider value={state}>
21-
<DispatchSwitch.Provider value={dispatch}>{childs}</DispatchSwitch.Provider>
10+
<DispatchSwitch.Provider value={dispatch}>{children}</DispatchSwitch.Provider>
2211
<Render />
2312
</Context.Provider>
2413
);

0 commit comments

Comments
 (0)