Skip to content

Commit

Permalink
fix: resolve @types/react@18 break change, React.FC
Browse files Browse the repository at this point in the history
  • Loading branch information
xg4 committed Apr 8, 2022
1 parent 3685b75 commit 20b7817
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 10 deletions.
5 changes: 4 additions & 1 deletion src/factory/createReducerContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ const createReducerContext = <R extends React.Reducer<any, any>>(
);
const providerFactory = (props, children) => createElement(context.Provider, props, children);

const ReducerProvider: React.FC<{ initialState?: React.ReducerState<R> }> = ({
const ReducerProvider = ({
children,
initialState,
}: {
children?: React.ReactNode;
initialState?: React.ReducerState<R>;
}) => {
const state = useReducer<R>(
reducer,
Expand Down
8 changes: 7 additions & 1 deletion src/factory/createStateContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ const createStateContext = <T>(defaultInitialValue: T) => {
createContext<[T, React.Dispatch<React.SetStateAction<T>>] | undefined>(undefined);
const providerFactory = (props, children) => createElement(context.Provider, props, children);

const StateProvider: React.FC<{ initialValue?: T }> = ({ children, initialValue }) => {
const StateProvider = ({
children,
initialValue,
}: {
children?: React.ReactNode;
initialValue?: T;
}) => {
const state = useState<T>(initialValue !== undefined ? initialValue : defaultInitialValue);
return providerFactory({ value: state }, children);
};
Expand Down
2 changes: 1 addition & 1 deletion src/useMedia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const getInitialState = (query: string, defaultState?: boolean) => {
if (isBrowser) {
return window.matchMedia(query).matches;
}

// A default value has not been provided, and you are rendering on the server, warn of a possible hydration mismatch when defaulting to false.
if (process.env.NODE_ENV !== 'production') {
console.warn(
Expand Down
9 changes: 7 additions & 2 deletions stories/useHarmonicIntervalFn.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import * as React from 'react';
import { useHarmonicIntervalFn, useInterval, useTimeoutFn } from '../src';
import ShowDocs from './util/ShowDocs';

const Clock: React.FC<{ useInt: typeof useHarmonicIntervalFn }> = ({ useInt }) => {
const Clock = ({
useInt,
}: {
children?: React.ReactNode;
useInt: typeof useHarmonicIntervalFn;
}) => {
const [count, setCount] = React.useState(0);
useInt(() => {
setCount((cnt) => cnt + 1);
Expand All @@ -25,7 +30,7 @@ const Clock: React.FC<{ useInt: typeof useHarmonicIntervalFn }> = ({ useInt }) =
return <div style={style}>{m + ':' + s}</div>;
};

const Demo: React.FC<{ useInt: typeof useHarmonicIntervalFn }> = ({ useInt }) => {
const Demo = ({ useInt }: { children?: React.ReactNode; useInt: typeof useHarmonicIntervalFn }) => {
const [showSecondClock, setShowSecondClock] = React.useState(false);
useTimeoutFn(() => {
setShowSecondClock(true);
Expand Down
2 changes: 1 addition & 1 deletion stories/useMouse.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as React from 'react';
import { useMouse } from '../src';
import ShowDocs from './util/ShowDocs';

const Demo: React.FC<any> = () => {
const Demo = () => {
const ref = React.useRef(null);
const state = useMouse(ref);

Expand Down
2 changes: 1 addition & 1 deletion stories/useMouseHovered.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as React from 'react';
import { useMouseHovered } from '../src';
import ShowDocs from './util/ShowDocs';

const Demo: React.FC<any> = ({ whenHovered, bound }) => {
const Demo = ({ whenHovered, bound }: any) => {
const ref = React.useRef(null);
const state = useMouseHovered(ref, { whenHovered, bound });

Expand Down
2 changes: 1 addition & 1 deletion stories/useMouseWheel.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as React from 'react';
import { useMouseWheel } from '../src';
import ShowDocs from './util/ShowDocs';

const Demo: React.FC<any> = () => {
const Demo = () => {
const mouseWheel = useMouseWheel();
return (
<>
Expand Down
2 changes: 1 addition & 1 deletion tests/createReducerContext.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('when using created hook', () => {

const setUp = () => {
const [useSharedNumber, SharedNumberProvider] = createReducerContext(reducer, 0);
const wrapper: React.FC = ({ children }) => (
const wrapper = ({ children }: { children?: React.ReactNode }) => (
<SharedNumberProvider>{children}</SharedNumberProvider>
);
return renderHook(() => useSharedNumber(), { wrapper });
Expand Down
4 changes: 3 additions & 1 deletion tests/createStateContext.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ describe('when using created hook', () => {

const setUp = () => {
const [useSharedText, SharedTextProvider] = createStateContext('init');
const wrapper: React.FC = ({ children }) => <SharedTextProvider>{children}</SharedTextProvider>;
const wrapper = ({ children }: { children?: React.ReactNode }) => (
<SharedTextProvider>{children}</SharedTextProvider>
);
return renderHook(() => useSharedText(), { wrapper });
};

Expand Down

0 comments on commit 20b7817

Please sign in to comment.