Raw text cannot be used outside of a <Text> tag when using style property
See original GitHub issueHi there,
I am probably doing something wrong, if not a lot of things, but I can’t figure out what. I have Googled, and I have read through the issues here, but to no avail.
In brief, after a recent upgrade on a project to "eslint-plugin-react-native": "^3.8.1"
, I’m getting all kinda warnings.
These seem to be only on <Text> elements where I have implemented in-line styles, but there’s so many, I’m not 100% sure.
If I delete the style prop, the warning goes away, but then so does the styling.
Here are a couple examples:
<Text style={{ ...theme.typography.subtitle, textAlign: "center" }}>
To optimize your experience...
</Text>
<Text
style={{
...theme.typography.title,
textAlign: "center"
}}
>
Connect
{primaryMusicStream === "spotify"
? " " + getPrimaryMusicStreamTitleCase(primaryMusicStream)
: null}
</Text>
<Text style={theme.typography.subtitle}>
Your Spotify playlist has been cleaned
</Text>
I’m not using StyleSheets, and theme.xxx
is referencing an imported style sheet that looks like this:
...
export const theme = {
dark: {
buttons: {
button: {
buttonStyle: {
backgroundColor: colors.primary,
borderRadius: 8,
width: 275
}
},
blockButton: {
containerStyle: { width: "100%" },
buttonStyle: {
backgroundColor: colors.primary,
borderRadius: 0
}
},
...
The only way to make this warning to away–aside from disabling the rule–is to use variables in lieu of text, like this:
<Text style={styles.emoticon}>{cleaner}</Text>
But that seems like a lot of work, that I’m loath to consider.
Any clues and/or advice would be most appreciated.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:6 (2 by maintainers)
Similar issue:
problem still exists in 3.10.0