@@ -19,7 +19,7 @@ const reMarkup = /<|&#?\w+;/;
19
19
export interface LocalizedProps {
20
20
id : string ;
21
21
attrs ?: Record < string , boolean > ;
22
- children ?: ReactNode ;
22
+ children ?: ReactNode | Array < ReactNode > ;
23
23
vars ?: Record < string , FluentVariable > ;
24
24
elems ?: Record < string , ReactElement > ;
25
25
}
@@ -46,13 +46,23 @@ export interface LocalizedProps {
46
46
* source code.
47
47
*/
48
48
export function Localized ( props : LocalizedProps ) : ReactElement {
49
- const { id, attrs, vars, elems, children : child = null } = props ;
49
+ const { id, attrs, vars, elems, children = null } = props ;
50
50
const l10n = useContext ( FluentContext ) ;
51
+ let child : ReactNode | null ;
52
+
53
+ // Validate that the child element isn't an array that contains multiple
54
+ // elements.
55
+ if ( Array . isArray ( children ) ) {
56
+ if ( children . length > 1 ) {
57
+ throw new Error ( "<Localized/> expected to receive a single " +
58
+ "React node child" ) ;
59
+ }
51
60
52
- // Validate that the child element isn't an array
53
- if ( Array . isArray ( child ) ) {
54
- throw new Error ( "<Localized/> expected to receive a single " +
55
- "React node child" ) ;
61
+ // If it's an array with zero or one element, we can directly get the first
62
+ // one.
63
+ child = children [ 0 ] ;
64
+ } else {
65
+ child = children ;
56
66
}
57
67
58
68
if ( ! l10n ) {
0 commit comments