Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(react): upgrade React typings to use a more explicit children prop declaration #6320

Merged
merged 6 commits into from
Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/auth/src/AuthProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,21 @@ type AuthProviderProps =
type: Omit<SupportedAuthTypes, 'dbAuth' | 'clerk'>
config?: never
skipFetchCurrentUser?: boolean
children?: React.ReactNode
}
| {
client?: never
type: 'clerk'
config?: never
skipFetchCurrentUser?: boolean
children?: React.ReactNode
}
| {
client?: WebAuthnClientType
type: 'dbAuth'
config?: SupportedAuthConfig
skipFetchCurrentUser?: boolean
children?: React.ReactNode
}

type AuthProviderState = {
Expand Down
1 change: 1 addition & 0 deletions packages/router/src/location.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface LocationProviderProps {
hash?: string
}
trailingSlashes?: TrailingSlashesTypes
children?: React.ReactNode
}

class LocationProvider extends React.Component<LocationProviderProps> {
Expand Down
1 change: 1 addition & 0 deletions packages/router/src/params.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const ParamsContext = createNamedContext<ParamsContextProps>('Params')
interface Props {
path?: string
location?: LocationContextType
children?: React.ReactNode
}

export const ParamsProvider: React.FC<Props> = ({
Expand Down
1 change: 1 addition & 0 deletions packages/router/src/router-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const RouterSetContext = createContext<
export interface RouterContextProviderProps
extends Omit<RouterState, 'useAuth'> {
useAuth?: typeof useAuth
children?: React.ReactNode
}

function stateReducer(state: RouterState, newState: Partial<RouterState>) {
Expand Down
3 changes: 2 additions & 1 deletion packages/router/src/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,10 @@ function isRoute(
return isReactElement(node) && node.type === Route
}

interface RouterProps extends RouterContextProviderProps {
export interface RouterProps extends RouterContextProviderProps {
trailingSlashes?: TrailingSlashesTypes
pageLoadingDelay?: number
children?: React.ReactNode
}

const Router: React.FC<RouterProps> = ({
Expand Down
1 change: 1 addition & 0 deletions packages/testing/src/web/MockParamsProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useLocation, ParamsContext, parseSearch } from '@redwoodjs/router'

interface Props {
path?: string
children?: React.ReactNode
}

export const MockParamsProvider: React.FC<Props> = ({ children }) => {
Expand Down
5 changes: 4 additions & 1 deletion packages/testing/src/web/MockProviders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ export const mockAuthClient: AuthClient = {
type: 'custom',
}

export const MockProviders: React.FunctionComponent = ({ children }) => {
// TODO(pc): see if there are props we want to allow to be passed into our mock provider (e.g. AuthProviderProps)
export const MockProviders: React.FunctionComponent<{
children?: React.ReactNode
}> = ({ children }) => {
return (
<AuthProvider client={mockAuthClient} type="custom">
<RedwoodProvider titleTemplate="%PageTitle | %AppTitle">
Expand Down
4 changes: 2 additions & 2 deletions packages/testing/src/web/MockRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import React from 'react'
// for jest and Storybook. Not doing so would cause an infinite loop.
// See: ./packages/core/config/src/configs/browser/jest.createConfig.ts
// @ts-ignore
import { isRoute } from '@redwoodjs/router/dist/router'
import { isRoute, RouterProps } from '@redwoodjs/router/dist/router'
import { flattenAll, replaceParams } from '@redwoodjs/router/dist/util'
// @ts-ignore
export * from '@redwoodjs/router/dist/index'
Expand All @@ -16,7 +16,7 @@ export const routes: { [routeName: string]: () => string } = {}
* We overwrite the default `Router` export.
* It populates the `routes.<pagename>()` utility object.
*/
export const Router: React.FunctionComponent = ({ children }) => {
export const Router: React.FunctionComponent<RouterProps> = ({ children }) => {
const flatChildArray = flattenAll(children)

flatChildArray.forEach((child) => {
Expand Down
3 changes: 3 additions & 0 deletions packages/web/src/apollo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ const ApolloProviderWithFetchConfig: React.FunctionComponent<{
}
useAuth: UseAuthProp
logLevel: F.Return<typeof setLogVerbosity>
children?: React.ReactNode
}> = ({ config, children, useAuth, logLevel }) => {
/**
* Should they run into it,
Expand Down Expand Up @@ -255,6 +256,7 @@ type ComponentDidCatch = React.ComponentLifecycle<any, any>['componentDidCatch']
interface ErrorBoundaryProps {
error?: unknown
onError: NonNullable<ComponentDidCatch>
children?: React.ReactNode
}

class ErrorBoundary extends React.Component<ErrorBoundaryProps> {
Expand All @@ -272,6 +274,7 @@ export const RedwoodApolloProvider: React.FunctionComponent<{
graphQLClientConfig?: GraphQLClientConfigProp
useAuth?: UseAuthProp
logLevel?: F.Return<typeof setLogVerbosity>
children?: React.ReactNode
}> = ({
graphQLClientConfig,
useAuth = useRWAuth,
Expand Down
1 change: 1 addition & 0 deletions packages/web/src/components/FetchConfigProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type UseAuthType = () => AuthContextInterface
*/
export const FetchConfigProvider: React.FunctionComponent<{
useAuth?: UseAuthType
children?: React.ReactNode
}> = ({
useAuth = global.__REDWOOD__USE_AUTH ?? (() => defaultAuthState),
...rest
Expand Down