Require text content to be wrapped in a <Text> (or an allowed) component. In React Native, only text inside <Text> is rendered; raw text or other elements used as text can cause issues or be invisible.
- Rule ID:
react-native/no-raw-text - Fixable: No
The rule flags:
- String literals used as JSX children outside of
<Text>(e.g.<View>hello</View>) - JSX text nodes outside of
<Text>(e.g.<View>hello</View>) - Template literals in expression containers outside of
<Text>
By default, the following are treated as valid text containers: Text, TSpan, StyledText, Animated.Text. You can allow more with the skip option.
<View>hello</View>
<View><span>Raw text</span></View><View><Text>hello</Text></View>
<View><Text>Raw text</Text></View>Raw text ({{value}}) cannot be used outside of a <Text> tag
or
Whitespace(s) cannot be used outside of a <Text> tag
skip(string[]): Extra component names to treat as allowed text parents (e.g. custom text components).
{
"react-native/no-raw-text": ["error", { "skip": ["MyText", "Label"] }]
}