question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Raw text cannot be used outside of a <Text> tag when using style property

See original GitHub issue

Hi 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:open
  • Created 3 years ago
  • Reactions:2
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
mjmasncommented, Sep 2, 2020

Similar issue:

export const Comp = () => {
  return (
    <Text>
      <Text>The quick brown fox jumped over the lazy dog</Text>{" "}
      {/* Whitespace(s) cannot be used outside of a <Text> tag   ^ */}
      <Text>The quick brown fox jumped over the lazy dog</Text>
    </Text>
  );
};
0reactions
pkecommented, Nov 16, 2020

problem still exists in 3.10.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

raw text cannot be used outside of a text tag. not rendering string
The issue is whitespace. Using "tabs" however does not count as whitespace. Try removing the space between the tag and the comment.
Read more >
eslint-plugin-react-native - Bountysource
Raw text cannot be used outside of a <Text> tag when using style property $ 0. Created 2 years ago in Intellicode/eslint-plugin-react-native with...
Read more >
text-rendering - CSS: Cascading Style Sheets - MDN Web Docs
The text-rendering CSS property provides information to the rendering engine about what to optimize for when rendering text.
Read more >
Docs • Svelte
Readonly props can be accessed as properties on the element, tied to the component using bind:this syntax. You can use reserved words as...
Read more >
Markdown Syntax Documentation - Daring Fireball
A Markdown-formatted document should be publishable as-is, as plain text, without looking like it's been marked up with tags or formatting instructions.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found