Skip to content
This repository has been archived by the owner on Jun 29, 2018. It is now read-only.

Create a React element #24

Open
mjhamm75 opened this issue Mar 22, 2016 · 6 comments
Open

Create a React element #24

mjhamm75 opened this issue Mar 22, 2016 · 6 comments
Labels

Comments

@mjhamm75
Copy link

How do I create a React element from the string that is returned from transform?

@Daniel15
Copy link
Member

Can you elaborate on exactly what you're trying to do? :)

@khankuan
Copy link

khankuan commented Jun 8, 2016

Hey, i had a similar question. I have something like:

import React from 'react';
const main = () => {
  return eval(Babel.transform(code, { presets: ['es2015', 'react']}).code)
}

But encountered React is not defined. Do you have any advice for it? Thanks!

@Daniel15
Copy link
Member

Daniel15 commented Jun 8, 2016

But encountered React is not defined.

You need to load React. Easiest way is to load it from Facebook's CDN:

<script src="https://fb.me/react-15.1.0.min.js"></script>
<script src="https://fb.me/react-dom-15.1.0.min.js"></script>

Also note that you can't use import statements with babel-standalone, as it does not provide any module system.

@khankuan
Copy link

khankuan commented Jun 8, 2016

Ah okie, basically window.React needs to be defined in my case

@khankuan
Copy link

khankuan commented Jun 8, 2016

If I have a component <MyButton />, is there a way to reference it?

@liekkas9
Copy link

liekkas9 commented Aug 1, 2017

@khankuan I also met the same scene, and I solved it in this way. I think it would not be the best way to mount all the objects on the window. Would you later find a better solution?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants