mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 19:07:08 +00:00
react-intl: change the FormattedMessage tagName prop to accept any ReactType (#31906)
In the react-intl source the prop is defined as follows:
tagName: PropTypes.oneOfType([PropTypes.string, PropTypes.element])
But it's actually passed straight to React.createElement(tagName, …),
so any type that is accepted by createElement should be allowed here.
It is useful to allow passing custom components to FormattedMessage,
for example when you use styled components, eg.
const FancyHeading = styled('h1')`font-size: 32px`;
<FormattedMessage … tagName={FancyHeading} />
This commit is contained in:
parent
1ff633d518
commit
08c13378e4
2
types/react-intl/index.d.ts
vendored
2
types/react-intl/index.d.ts
vendored
@ -146,7 +146,7 @@ declare namespace ReactIntl {
|
||||
|
||||
interface Props extends MessageDescriptor {
|
||||
values?: {[key: string]: MessageValue | JSX.Element};
|
||||
tagName?: string;
|
||||
tagName?: React.ReactType;
|
||||
children?: (...formattedMessage: Array<string | JSX.Element>) => React.ReactNode;
|
||||
}
|
||||
}
|
||||
|
||||
@ -156,6 +156,13 @@ class SomeComponent extends React.Component<SomeComponentProps & InjectedIntlPro
|
||||
values={{ blank: null, empty: undefined }}
|
||||
tagName="div" />
|
||||
|
||||
<FormattedMessage
|
||||
id="test"
|
||||
description="Test"
|
||||
defaultMessage="Hi {blank} and {empty}!"
|
||||
values={{ blank: null, empty: undefined }}
|
||||
tagName={({ children }) => <div>{children}</div>} />
|
||||
|
||||
<FormattedMessage
|
||||
id="test"
|
||||
description="Test"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user