From a5c6e2fc144f82dfe0b3960faab7bf9a5d489371 Mon Sep 17 00:00:00 2001 From: razinj Date: Mon, 24 Apr 2023 16:14:47 +0100 Subject: [PATCH] Use proper type for children Using 'PropsWithChildren' --- src/components/Settings/shared/ToggleSettings.tsx | 6 ++---- src/contexts/SearchContextWrapper.tsx | 8 ++------ utils/test/utils.tsx | 6 +++--- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/components/Settings/shared/ToggleSettings.tsx b/src/components/Settings/shared/ToggleSettings.tsx index f7adee6..82c199b 100644 --- a/src/components/Settings/shared/ToggleSettings.tsx +++ b/src/components/Settings/shared/ToggleSettings.tsx @@ -1,12 +1,10 @@ -import React, { ReactNode, useState } from 'react' +import React, { PropsWithChildren, useState } from 'react' import { Pressable, StyleSheet, View } from 'react-native' import CustomIcon from '../../shared/CustomIcon' import SettingsItemLabel, { SettingsItemLabelProps } from './SettingsItemLabel' import { settingItemButtonRippleConfig } from './values' -type Props = SettingsItemLabelProps & { - children: ReactNode -} +type Props = PropsWithChildren const ToggleSettings = ({ title, description, children }: Props) => { const [renderSettings, setRenderSettings] = useState(false) diff --git a/src/contexts/SearchContextWrapper.tsx b/src/contexts/SearchContextWrapper.tsx index 5148744..755ec15 100644 --- a/src/contexts/SearchContextWrapper.tsx +++ b/src/contexts/SearchContextWrapper.tsx @@ -1,12 +1,8 @@ -import React, { ReactNode, RefObject, useMemo, useRef } from 'react' +import React, { PropsWithChildren, RefObject, useMemo, useRef } from 'react' import { TextInput } from 'react-native' import SearchContext, { SearchContextType } from './SearchContext' -type Props = { - children: ReactNode -} - -const SearchContextWrapper = ({ children }: Props) => { +const SearchContextWrapper = ({ children }: PropsWithChildren) => { const searchInputRef: RefObject | null = useRef(null) const clearSearchInput = () => { diff --git a/utils/test/utils.tsx b/utils/test/utils.tsx index 78008af..135d25b 100644 --- a/utils/test/utils.tsx +++ b/utils/test/utils.tsx @@ -1,6 +1,6 @@ import { configureStore, PreloadedState, Store } from '@reduxjs/toolkit' import { render, RenderOptions } from '@testing-library/react-native' -import React, { ReactElement, ReactNode } from 'react' +import React, { PropsWithChildren, ReactElement } from 'react' import { Provider as PaperProvider } from 'react-native-paper' import { Provider as StoreProvider } from 'react-redux' import SearchContext, { SearchContextType } from '../../src/contexts/SearchContext' @@ -22,7 +22,7 @@ export const renderWithProvider = ( ...renderOptions }: ExtendedRenderOptions = {} ) => { - const wrapper = ({ children }: { children: ReactNode }): JSX.Element => { + const wrapper = ({ children }: PropsWithChildren): JSX.Element => { return ( {children} @@ -43,7 +43,7 @@ export const renderWithProviderAndContexts = ( ...renderOptions }: ExtendedRenderOptions = {} ) => { - const wrapper = ({ children }: { children: ReactNode }): JSX.Element => { + const wrapper = ({ children }: PropsWithChildren): JSX.Element => { return (