Closed ugrky closed 4 years ago
Great question. For people who use typescript, then the types are great. However, any developers who use this library in a non-typescript project need PropTypes to ensure that React stops them from passing in invalid props. I'm not sure how libraries that support web handle this use case, maybe you could see how they do type enforcement for non-typescript projects and let me know?
@SteffeyDev asked me to weigh in here. I only use TypeScript, so I’m not sure, but this might be relevant to https://github.com/necolas/react-native-web/issues/1684
Just updated my comment with the correct link.
Not sure if I missed it, does that issue relate to PropTypes at all?
Oh I see, this only relates to proptypes, not flow types, sorry got them mixed up since I don’t use either.
@SteffeyDev I ran into the same problem as this issue with react-native-calendars
. I figured out a solution there.
All you have to do is conditionally import ViewPropTypes
from react-native
, and not import it on web. RNW removed it from the package since React Native plans on deprecating it.
This was the solution in react-native-calendars
:
import { View, Platform } from 'react-native'
const viewPropTypes =
typeof document !== 'undefined' || Platform.OS === 'web'
? PropTypes.shape({ style: PropTypes.object })
: require('react-native').ViewPropTypes || View.propTypes
Ah very cool, I'll add this in and see if it works
To please TS, you might need to make the web type as any
.
Actually TS has a problem with document
and the fact that View
does not have a member propTypes
. I think I can exclude the document !== 'undefined'
check, where did you get View.propTypes
from?
Wix included that in their calendar library. I've never used prop types so I just copied that part over.
Interesting. Don't think I need that either.
Ok, this is done in the latest release, thanks for finding a good solution!
Is your feature request related to a problem? Please describe. I am currently trying to run the library on
react-native-web
. I know that the library is not officially supported on web, but would be nice to make it work. I will be doing some changes on my own fork, but wanted to use this thread as a platform to discuss a few things.react-native-web
has unspoortedViewPropTypes
as of 0.12. Therefore, I get the following error:Caused by the following lines:
Describe the solution you'd like First I want to ask you why is
PropTypes
used in this repo while there is already great TypeScript implementation. If we get rid of PropTypes, it will work onreact-native-web
too. I will work on further improvements to make this library work on web, but I think it would be the first step.I would be happy if you could inform me why you choose to opt in for PropTypes.
Thanks in advance!