Skip to content

Commit 30e5242

Browse files
authored
fix: remove VFC, FC type usage (#2290)
1 parent 80a19ca commit 30e5242

File tree

4 files changed

+26
-32
lines changed

4 files changed

+26
-32
lines changed

examples/rspack/src/react-env.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ declare module "*.gif" {
122122
export default src;
123123
}
124124
declare module "*.svg" {
125-
const ReactComponent: React.FC<React.SVGProps<SVGSVGElement>>;
125+
const ReactComponent: (props: React.SVGProps<SVGSVGElement>) => React.ReactNode;
126126
const content: string;
127127

128128
// export { ReactComponent };

packages/react/macro/index.d.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ReactNode, VFC, FC } from "react"
1+
import type { ReactNode } from "react"
22
import type { TransRenderCallbackOrComponent, I18nContext } from "@lingui/react"
33
import type {
44
MacroMessageDescriptor,
@@ -52,7 +52,7 @@ type SelectChoiceProps = {
5252
* <Trans id="custom.id">Hello {username}.</Trans>
5353
* ```
5454
*/
55-
export const Trans: FC<TransProps>
55+
export const Trans: (props: TransProps) => ReactNode
5656

5757
/**
5858
* Props of Plural macro are transformed into plural format.
@@ -67,7 +67,7 @@ export const Trans: FC<TransProps>
6767
* <Trans id="{numBooks, plural, one {Book} other {Books}}" values={{ numBooks }} />
6868
* ```
6969
*/
70-
export const Plural: VFC<PluralChoiceProps>
70+
export const Plural: (props: PluralChoiceProps) => ReactNode
7171
/**
7272
* Props of SelectOrdinal macro are transformed into selectOrdinal format.
7373
*
@@ -86,7 +86,7 @@ export const Plural: VFC<PluralChoiceProps>
8686
* />
8787
* ```
8888
*/
89-
export const SelectOrdinal: VFC<PluralChoiceProps>
89+
export const SelectOrdinal: (props: PluralChoiceProps) => ReactNode
9090

9191
/**
9292
* Props of Select macro are transformed into select format
@@ -105,7 +105,7 @@ export const SelectOrdinal: VFC<PluralChoiceProps>
105105
* />
106106
* ```
107107
*/
108-
export const Select: VFC<SelectChoiceProps>
108+
export const Select: (props: SelectChoiceProps) => ReactNode
109109

110110
declare function _t(descriptor: MacroMessageDescriptor): string
111111
declare function _t(

packages/react/src/I18nProvider.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { ComponentType, FunctionComponent } from "react"
1+
import React, { ComponentType } from "react"
22
import type { I18n } from "@lingui/core"
33
import type { TransRenderProps } from "./TransNoContext"
44

@@ -31,11 +31,11 @@ export function useLingui(): I18nContext {
3131
return useLinguiInternal()
3232
}
3333

34-
export const I18nProvider: FunctionComponent<I18nProviderProps> = ({
34+
export function I18nProvider({
3535
i18n,
3636
defaultComponent,
3737
children,
38-
}) => {
38+
}: I18nProviderProps) {
3939
const latestKnownLocale = React.useRef<string | undefined>(i18n.locale)
4040
/**
4141
* We can't pass `i18n` object directly through context, because even when locale

packages/react/src/Trans.test.tsx

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,10 @@ describe("Trans component", () => {
270270
})
271271

272272
it("should render nested elements with `asChild` pattern", () => {
273-
const ComponentThatExpectsSingleElementChild: React.FC<{
273+
function ComponentThatExpectsSingleElementChild(props: {
274274
asChild: boolean
275275
children?: React.ReactElement
276-
}> = (props) => {
276+
}) {
277277
if (props.asChild && React.isValidElement(props.children)) {
278278
return props.children
279279
}
@@ -387,9 +387,7 @@ describe("Trans component", () => {
387387
})
388388

389389
it("should take defaultComponent prop with a custom component", () => {
390-
const ComponentFC: React.FunctionComponent<TransRenderProps> = (
391-
props
392-
) => {
390+
function ComponentFC(props: TransRenderProps) {
393391
return <div>{props.children}</div>
394392
}
395393
const span = render(
@@ -406,9 +404,7 @@ describe("Trans component", () => {
406404
])(
407405
"should ignore defaultComponent when `component` or `render` is null",
408406
(props) => {
409-
const ComponentFC: React.FunctionComponent<TransRenderProps> = (
410-
props
411-
) => {
407+
function ComponentFC(props: TransRenderProps) {
412408
return <div>{props.children}</div>
413409
}
414410
const translation = render(
@@ -434,9 +430,7 @@ describe("Trans component", () => {
434430

435431
it("should render function component as simple prop", () => {
436432
const propsSpy = jest.fn()
437-
const ComponentFC: React.FunctionComponent<TransRenderProps> = (
438-
props
439-
) => {
433+
function ComponentFC(props: TransRenderProps) {
440434
propsSpy(props)
441435
const [state] = React.useState("value")
442436
return <div id={props.id}>{state}</div>
@@ -454,18 +448,18 @@ describe("Trans component", () => {
454448
})
455449

456450
describe("I18nProvider defaultComponent accepts render-like props", () => {
457-
const DefaultComponent: React.FunctionComponent<TransRenderProps> = (
458-
props
459-
) => (
460-
<>
461-
<div data-testid="children">{props.children}</div>
462-
{props.id && <div data-testid="id">{props.id}</div>}
463-
{props.message && <div data-testid="message">{props.message}</div>}
464-
{props.translation && (
465-
<div data-testid="translation">{props.translation}</div>
466-
)}
467-
</>
468-
)
451+
function DefaultComponent(props: TransRenderProps) {
452+
return (
453+
<>
454+
<div data-testid="children">{props.children}</div>
455+
{props.id && <div data-testid="id">{props.id}</div>}
456+
{props.message && <div data-testid="message">{props.message}</div>}
457+
{props.translation && (
458+
<div data-testid="translation">{props.translation}</div>
459+
)}
460+
</>
461+
)
462+
}
469463

470464
it("should render defaultComponent with Trans props", () => {
471465
const markup = render(

0 commit comments

Comments
 (0)