2017-06-26 39 views
0

這聽起來像一個奇怪的問題。它是。但是有可能在我用create-react-app實例化的反應應用程序中做這樣的事情嗎?在香草React應用中包含react-native組件

import React, { Component } from 'react'; 
import { Text, View, StyleSheet } from 'react-native'; 
... 

也就是說,即使我不能真正建立在移動的看法,我希望把它列入我的代碼做別的事情與它

我只問,因爲我無法在 各地得到"Module not found: Can't resolve 'react-native' in '/Users/...'錯誤,即使在我的package.json react-native

回答

1

嗯......事情是,react-native將僅適用於本地應用程序的工作,如果你需要使用這些組件,你將不得不使用其他如react-本機的網絡。

https://github.com/necolas/react-native-web

這可能是你在找什麼。

1

你在找什麼是react-primitives

這個庫試圖提出一個理想的基元集合,圍繞 構建React應用程序,而不管平臺如何。將來, 這可以用作不使用特定於平臺的API的React和React Native 組件之間的共享接口。

然後,您從此包中導入某些基元。它們將以本機和/或DOM呈現。

import React, { Component } from 'react'; 
import { Text, StyleSheet } from 'react-primitives'; 

export function CrossplatformComponent() { 
    return <Text>Hello world</Text> 
}