Skip to content
This repository has been archived by the owner on Aug 28, 2022. It is now read-only.

Commit

Permalink
Add React compatibility layer
Browse files Browse the repository at this point in the history
This suppresses warnings for projects which do not include PropTypes or versions of React less than 15.5.
  • Loading branch information
eliperkins committed Jul 28, 2017
1 parent c001c9a commit 19572f9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/create-glamorous.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import PropTypes from 'prop-types';
import PropTypes from './react-compat';
import React from 'react';
import {StyleSheet} from 'react-native'
import {CHANNEL} from './constants'
Expand Down
15 changes: 15 additions & 0 deletions src/react-compat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react'

// eslint-disable-next-line import/no-mutable-exports
let PropTypes

if (parseFloat(React.version.slice(0, 4)) >= 15.5) {
try {
PropTypes = require('prop-types')
} catch (error) {
// ignore
}
}
PropTypes = PropTypes || React.PropTypes

export default PropTypes
2 changes: 1 addition & 1 deletion src/theme-provider.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import PropTypes from 'prop-types';
import PropTypes from './react-compat';
import React from 'react';
import brcast from 'brcast'
import {CHANNEL} from './constants'
Expand Down
2 changes: 1 addition & 1 deletion src/with-theme.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import PropTypes from 'prop-types';
import PropTypes from './react-compat';
import React from 'react';
import {CHANNEL} from './constants'

Expand Down

0 comments on commit 19572f9

Please sign in to comment.