You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
common/Input: Avoid not-recommended way of using react-intl API.
Following from discussion on GitHub [1].
We would have a bug if multiple chunks were passed to the render
callback prop [2], since we're just using the first one. It looks
like multiple chunks won't be passed, since we haven't explicitly
made that happen.
Glad to have this API misuse exposed by the API change in
`react-intl` v5, which we took in a recent commit:
"`FormattedMessage` render prop is no longer variadic".
But we don't need to use this render prop pattern at all. From the
docs [3]:
"""
If you need to customize rendering, you can either [...] or pass a
function as the child.
"""
We just need plain old strings, without customization. So, just do
the more straightforward thing we do in a bunch of places: use
`formatMessage` as it's wrapped by `_`. Plumb through `_` using
`withGetText` as recommended by the JSDoc for `GetText`:
"""
Alternatively, for when `context` is already in use: use
`withGetText` and then say `const { _ } = this.props`.
"""
[1] #4222 (comment)
[2] The render callback prop's name is `children`. The "Function as
Child Component" pattern is sometimes opposed because `children`
is rarely an appropriate, expressive name; see, e.g.,
https://americanexpress.io/faccs-are-an-antipattern/. Here, it
also doesn't seem to be well-typed in the libdef. I'm unsure if
the "FaCC" pattern makes it especially hard to get well-typed,
but it seems plausible.
[3] #4222 (comment)
0 commit comments