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.

Crashing when using style prop that is a string

See original GitHub issue

Here is the crashing error:

ESLint: 7.20.0
TypeError: Cannot read property 'type' of undefined
Occurred while linting /myuser/myapp/src/screens/Walkthrough.tsx:82
    at JSXAttribute (/myuser/myapp/node_modules/eslint-plugin-react-native/lib/rules/no-single-element-style-arrays.js:40:35)
    at /myuser/myapp/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (/myuser/myapp/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/myuser/myapp/node_modules/eslint/lib/linter/node-event-generator.js:256:26)
    at NodeEventGenerator.applySelectors (/myuser/myapp/node_modules/eslint/lib/linter/node-event-generator.js:285:22)
    at NodeEventGenerator.enterNode (/myuser/myapp/node_modules/eslint/lib/linter/node-event-generator.js:299:14)
    at CodePathAnalyzer.enterNode (/myuser/myapp/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:711:23)
    at /myuser/myapp/node_modules/eslint/lib/linter/linter.js:954:32
    at Array.forEach (<anonymous>)

This is caused because the StatusBar component from Expo has a style prop that can be auto, inverted, light, or dark. Here is the snippet where is crashing:

<StatusBar style="light" backgroundColor={COLORS.PRIMARY[500]} animated />

This, is not:

<StatusBar style={"light"} backgroundColor={COLORS.PRIMARY[500]} animated />

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:7
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
Intellicodecommented, May 20, 2021

@AlanSl, just made a release, hope it works! If it breaks let me know.

2reactions
andre-m5vcommented, Mar 30, 2021

As a temporary workaround you could assign the style string to a variable:

const statusBarStyle = 'light';

and then use that as your style:

<StatusBar style={ statusBarStyle } />

This will prevent eslint from crashing. Then ofc you will get the react/style-prop-object rule error, but you can fix this by adding StatusBar as an exception in your rules.

Read more comments on GitHub >

github_iconTop Results From Across the Web

App crash in release mode when using 'View.propTypes.style'
View.propTypes.style isn't valid and printed a deprecation message for several releases before it was removed. Use ViewPropTypes.style instead.
Read more >
Material UI Select component crashing React application
Made sure value prop is an empty string, with a child matching MenuItem (no luck); Set a defaultValue prop (no luck); Removing other...
Read more >
8 Practices In React That Will Crash Your App In The Future
If it is a string, then the caller passed in the videoType so we can skip first step. Someone has found that the...
Read more >
UILabel Crash with Attributed Text | Apple Developer Forums
In Xcode version 10.0 and swift 4.2 my app crashes when setting the content of UILabel.attributedText and accessing any of UILabels variables. For...
Read more >
Handling common HTML and CSS problems - MDN Web Docs
Unrecognized HTML elements are treated by the browser as anonymous inline elements (effectively inline elements with no semantic value, similar ...
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