Skip to content

Commit 1748ea0

Browse files
committed
Merge pull request #2 from enterline/fix-formatted-message
Fix FormattedMessage so it works with children
2 parents 761d07f + e199658 commit 1748ea0

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/FormattedMessage.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1-
import React, { PropTypes } from 'react';
1+
import React, { PropTypes, isValidElement, createElement } from 'react';
22
import { Text } from 'react-native';
33
import Intl from 'react-intl';
44

55
const FormattedMessage = props => (
66
<Intl.FormattedMessage {...props}>
7-
{localized => <Text style={props.style}>{localized}</Text>}
7+
{(...nodes) => {
8+
const newNodes = nodes.map((node) => {
9+
if (!isValidElement(node)) {
10+
return (<Text style={props.style}>{node}</Text>);
11+
}
12+
return node;
13+
});
14+
return createElement(Text, null, ...newNodes);
15+
}}
816
</Intl.FormattedMessage>
917
);
1018

0 commit comments

Comments
 (0)