0

It sounds like a weird question. It is. But is it possible to do something like this in a react app that I instantiated with create-react-app?

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

i.e. even if I can't actually build the mobile view, I want to include it in my code to do something else with it

I only ask because I can't get around a "Module not found: Can't resolve 'react-native' in '/Users/...' error, even with react-native in my package.json

2 Answers 2

1

well... the thing is that react-native will only work for native apps, if you need to use those components, you will have to use an alternative such as react-native-web.

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

This might be what you are looking for.

Sign up to request clarification or add additional context in comments.

Comments

1

What you are looking for is react-primitives.

This library attempts to propose an ideal set of primitives around building React applications, regardless of Platform. In the future, this could be used as a shared interface among React and React Native components that don't use platform-specific APIs.

Then, you import certain primitives from this package. They will render in native and/or DOM.

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.