0.0.1 • Published 5 years ago

react-universal-xp v0.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

react-universal-xp

Universal interface to react-native-web and react-native

This is an alternative solution to using react-primitives. There should be no issues with using react-universal-xp components together with react-primitives components.

LICENSE: MIT LICENSE

Usage

Sample:

/** @jsx h */
import { createElement as h } from 'react'

import { Text, View } from 'react-universal-xp'

const headerBackgroundStyle = {backgroundColor: 'blue'}

const headerTextStyle = {color: 'gold', fontSize: 48}

function App() {
  return (
    <View style={headerBackgroundStyle}>
      <View>
        <Text style={headerTextStyle}>
          ☆☆ ☆☆☆ ☆☆
        </Text>
      </View>
      <View>
        <Text style={headerTextStyle}>
          ☆ Demo app ☆
        </Text>
      </View>
    </View>
  )
}

export default App

How it works

This module imports from react-native-web if either of the following is true:

  • existence of a Truthy global.document object
  • the is-node package indicates that the process is running in Node.js (as needed to work on a Razzle web server)

Otherwise, this module imports from react-native.

Here is the entire implementation in index.js, as an ES5 module:

/** detects if this is in a browser or Node.js web server */
var isWeb = (!!global.document || require('is-node'))

var universalExports = isWeb
  ? require('react-native-web')
  : require('react-native')

module.exports = universalExports

Major TODO items

References

License

MIT LICENSE