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.

Wrong PropType for style props in 2.0.0

See original GitHub issue

Bug report

In 2.0.0 PropTypes for a lot of styles have been changed from ViewPropTypes.style to PropTypes.object (see PR#2338 for example). However this is incorrect.

The prop type for styles should not be PropTypes.object as this will lead to React warnings when providing arrays, e.g. like this:

<Header containerStyle={[t.borderB0, t.pX1, t.pY1, { backgroundColor: "white" }]} ... />

Warning: Failed prop type. Invalid prop containerStyle of type array supplied to Header, expected object

Meany people might not be familiar with this syntax but it is perfectly legal and commonly used with frameworks such as Tailwind CSS and similar.

A simple fix would be to replace all occurrences of PropTypes.object for styles with PropTypes.oneOfType([PropTypes.object, PropTypes.array]) instead.

Environment info

System:
    OS: macOS 10.15.4
    CPU: (8) x64 Intel(R) Core(TM) i7-7920HQ CPU @ 3.10GHz
    Memory: 500.18 MB / 16.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 12.14.1 - ~/.nvm/versions/node/v12.14.1/bin/node
    npm: 6.14.5 - ~/.nvm/versions/node/v12.14.1/bin/npm
  SDKs:
    iOS SDK:
      Platforms: iOS 13.5, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
    Android SDK:
      API Levels: 19, 22, 23, 28, 29
      Build Tools: 28.0.3, 29.0.3, 30.0.0
      System Images: android-22 | Google APIs ARM EABI v7a, android-22 | Google APIs Intel x86 Atom, android-23 | Android Wear ARM EABI v7a, android-23 | Google APIs ARM EABI v7a, android-23 | Google APIs Intel x86 Atom, android-28 | Wear OS Intel x86 Atom, android-28 | Google APIs Intel x86 Atom, android-28 | Google Play Intel x86 Atom, android-29 | Google APIs Intel x86 Atom, android-29 | Google Play Intel x86 Atom, android-R | Google Play Intel x86 Atom
  IDEs:
    Android Studio: 4.0 AI-193.6911.18.40.6514223
    Xcode: 11.5/11E608c - /usr/bin/xcodebuild
  npmPackages:
    react: ~16.9.0 => 16.9.0 
    react-native: ~0.61.4 => 0.61.5

Library version: x.x.x

Steps to reproduce

Pass styles as array like this will generate a PropTypes warning:

<Header containerStyle={[{ padding: 1 }, { backgroundColor: "white" }]} ... />

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
flyingcirclecommented, Jun 7, 2020

@arabold I agree, but it wasn’t due to any changes made here or in 2.0.1 or 2.0.2. I would guess that if you moved to 1.2.7, you would see the same warning. This is a separate issue that someone would need to write a issue ticket on.

1reaction
araboldcommented, Jun 7, 2020

Absolutely! I only fixed the styles property in my original PR. I’ll probably create a new one if nobody else is quicker.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Don't Call PropTypes Warning - React
bool . This pattern by itself is fine, but triggers a false positive because React thinks you are calling PropTypes directly. The next...
Read more >
Getting error "PropTypes is not defined" in React
Well, this code throws an error in console - "PropTypes is not defined", so application does not render. Any ideas what's wrong in ......
Read more >
Packaging and PropTypes - Fullstack React
We're looking at how to make reusable React components today so we can share our components across apps and teams.
Read more >
How to forget about type errors in your React props with ...
In this article, we will be looking at how to making your debugging process faster with prop types in React, what they are,...
Read more >
function component is not a function declaration airbnb - You.com ...
"Missing return type on function" error in styled component interpolation ... Is it OK to put propTypes and defaultProps as static props inside...
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