dabbott / javascript-playgrounds

An interactive JavaScript sandbox
https://unpkg.com/javascript-playgrounds/public/index.html
Other
1.4k stars 131 forks source link

How to embed React Native code inside WebPlayer's code prop? #38

Closed szulima closed 4 years ago

szulima commented 5 years ago

Hey guys, I learn coding, want to use your tool and have silly question, can you please help me? Trying to embed React Native code inside of WebPlayer component (in React app) like that:

import React from 'react';
import WebPlayer from 'react-native-web-player';
import { AppRegistry, Text, } from 'react-native';

export default () => (
  <WebPlayer
    style={{width: 800, height: 500}}
    code={

      import React, { Component, } from 'react';
      import { AppRegistry, Text, } from 'react-native';
      const App = () => <Text>Hello World</Text>;
      AppRegistry.registerComponent('App', () => App);

    }
  />
)

I guess I don't know how to format code inside "code" parameter? Can you take a look?

dabbott commented 4 years ago

Sorry I missed this. The code needs to be a string, e.g.:

const code = `
import React, { Component, } from 'react';
import { AppRegistry, Text, } from 'react-native';
const App = () => <Text>Hello World</Text>;
AppRegistry.registerComponent('App', () => App);
`

export default () => (
  <WebPlayer
    style={{width: 800, height: 500}}
    code={code}
  />
)