Skip to content

Commit a7578ac

Browse files
authored
Merge pull request #2317 from xg4/fix-type
fix: resolve @types/react@18 break change, React.FC
2 parents 3685b75 + 20b7817 commit a7578ac

9 files changed

+26
-10
lines changed

src/factory/createReducerContext.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ const createReducerContext = <R extends React.Reducer<any, any>>(
1010
);
1111
const providerFactory = (props, children) => createElement(context.Provider, props, children);
1212

13-
const ReducerProvider: React.FC<{ initialState?: React.ReducerState<R> }> = ({
13+
const ReducerProvider = ({
1414
children,
1515
initialState,
16+
}: {
17+
children?: React.ReactNode;
18+
initialState?: React.ReducerState<R>;
1619
}) => {
1720
const state = useReducer<R>(
1821
reducer,

src/factory/createStateContext.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ const createStateContext = <T>(defaultInitialValue: T) => {
55
createContext<[T, React.Dispatch<React.SetStateAction<T>>] | undefined>(undefined);
66
const providerFactory = (props, children) => createElement(context.Provider, props, children);
77

8-
const StateProvider: React.FC<{ initialValue?: T }> = ({ children, initialValue }) => {
8+
const StateProvider = ({
9+
children,
10+
initialValue,
11+
}: {
12+
children?: React.ReactNode;
13+
initialValue?: T;
14+
}) => {
915
const state = useState<T>(initialValue !== undefined ? initialValue : defaultInitialValue);
1016
return providerFactory({ value: state }, children);
1117
};

src/useMedia.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const getInitialState = (query: string, defaultState?: boolean) => {
1010
if (isBrowser) {
1111
return window.matchMedia(query).matches;
1212
}
13-
13+
1414
// A default value has not been provided, and you are rendering on the server, warn of a possible hydration mismatch when defaulting to false.
1515
if (process.env.NODE_ENV !== 'production') {
1616
console.warn(

stories/useHarmonicIntervalFn.story.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ import * as React from 'react';
33
import { useHarmonicIntervalFn, useInterval, useTimeoutFn } from '../src';
44
import ShowDocs from './util/ShowDocs';
55

6-
const Clock: React.FC<{ useInt: typeof useHarmonicIntervalFn }> = ({ useInt }) => {
6+
const Clock = ({
7+
useInt,
8+
}: {
9+
children?: React.ReactNode;
10+
useInt: typeof useHarmonicIntervalFn;
11+
}) => {
712
const [count, setCount] = React.useState(0);
813
useInt(() => {
914
setCount((cnt) => cnt + 1);
@@ -25,7 +30,7 @@ const Clock: React.FC<{ useInt: typeof useHarmonicIntervalFn }> = ({ useInt }) =
2530
return <div style={style}>{m + ':' + s}</div>;
2631
};
2732

28-
const Demo: React.FC<{ useInt: typeof useHarmonicIntervalFn }> = ({ useInt }) => {
33+
const Demo = ({ useInt }: { children?: React.ReactNode; useInt: typeof useHarmonicIntervalFn }) => {
2934
const [showSecondClock, setShowSecondClock] = React.useState(false);
3035
useTimeoutFn(() => {
3136
setShowSecondClock(true);

stories/useMouse.story.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as React from 'react';
33
import { useMouse } from '../src';
44
import ShowDocs from './util/ShowDocs';
55

6-
const Demo: React.FC<any> = () => {
6+
const Demo = () => {
77
const ref = React.useRef(null);
88
const state = useMouse(ref);
99

stories/useMouseHovered.story.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as React from 'react';
44
import { useMouseHovered } from '../src';
55
import ShowDocs from './util/ShowDocs';
66

7-
const Demo: React.FC<any> = ({ whenHovered, bound }) => {
7+
const Demo = ({ whenHovered, bound }: any) => {
88
const ref = React.useRef(null);
99
const state = useMouseHovered(ref, { whenHovered, bound });
1010

stories/useMouseWheel.story.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as React from 'react';
33
import { useMouseWheel } from '../src';
44
import ShowDocs from './util/ShowDocs';
55

6-
const Demo: React.FC<any> = () => {
6+
const Demo = () => {
77
const mouseWheel = useMouseWheel();
88
return (
99
<>

tests/createReducerContext.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe('when using created hook', () => {
3333

3434
const setUp = () => {
3535
const [useSharedNumber, SharedNumberProvider] = createReducerContext(reducer, 0);
36-
const wrapper: React.FC = ({ children }) => (
36+
const wrapper = ({ children }: { children?: React.ReactNode }) => (
3737
<SharedNumberProvider>{children}</SharedNumberProvider>
3838
);
3939
return renderHook(() => useSharedNumber(), { wrapper });

tests/createStateContext.test.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ describe('when using created hook', () => {
1818

1919
const setUp = () => {
2020
const [useSharedText, SharedTextProvider] = createStateContext('init');
21-
const wrapper: React.FC = ({ children }) => <SharedTextProvider>{children}</SharedTextProvider>;
21+
const wrapper = ({ children }: { children?: React.ReactNode }) => (
22+
<SharedTextProvider>{children}</SharedTextProvider>
23+
);
2224
return renderHook(() => useSharedText(), { wrapper });
2325
};
2426

0 commit comments

Comments
 (0)