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.

define propTypes for compatibility

See original GitHub issue

Hi,

a lot of react-native libraries use ReactNative.Text.propTypes.style or ReactNative.ViewPropTypes to define their own propTypes.

I know that propTypes are deprecated, but right now this causes a lot of “cannot read property style of undefined” errors with third party libraries.

My workaround is to monkey patch the prop types:

import * as ReactNative from 'react-native-web';
{
  const PropTypes = require('prop-types');
  ReactNative.Text.propTypes = { style: PropTypes.any };
  ReactNative.View.propTypes = { style: PropTypes.any };
  ReactNative.Image.propTypes = { style: PropTypes.any };
  ReactNative.ViewPropTypes = { style: PropTypes.any };
}

I wonder if it makes sense to have the propTypes still defined by react-native-web for better user experience or just wait until propTypes are removed from the third party libraries.

Cheers Mo

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
LinusUcommented, Feb 27, 2020

Would you mind sharing which libraries this is? I think that the correct course is to send PRs to them ☺️

0reactions
phpepecommented, Aug 19, 2022

Hey @mo22, I like your workaround. On which file are you adding this ?

import * as ReactNative from 'react-native-web';
{
 const PropTypes = require('prop-types');
 ReactNative.Text.propTypes = { style: PropTypes.any };
 ReactNative.View.propTypes = { style: PropTypes.any };
 ReactNative.Image.propTypes = { style: PropTypes.any };
 ReactNative.ViewPropTypes = { style: PropTypes.any };
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Typechecking With PropTypes - React
PropTypes exports a range of validators that can be used to make sure the data you receive is valid. In this example, we're...
Read more >
prop-types - npm
Start using prop-types in your project by running `npm i prop-types`. ... This package is compatible with React 15.3.0 and higher.
Read more >
How to define propTypes for a Component that only passes ...
3 Answers 3 · your first spread is not necessary : Parent.propTypes = { p0: PropTypes.string.isRequired ...Child. · in that case, you can...
Read more >
react propTypes
PropTypes exports a range of validators that can be used to make sure the data you receive is valid. In this example, we're...
Read more >
How to use the react-select.propTypes function in react ... - Snyk
node, value: PropTypes.any, }) ), // react-select knows this as multi, but for standardization // and compatibility we use multiple multiple ...
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