Skip to content

Instantly share code, notes, and snippets.

Created December 28, 2015 01:10
What would you like to do?
React Getting Started - How it should be!
import React from 'react'
import ReactDOM from 'react-dom'
const Hello = ({name}) => <h1>Hello {name}!</h1>
<Hello name={"vjeux"}/>,
<!DOCTYPE html>
<script src=""></script>
transpiler: 'babel', // or 'traceur' or 'typescript'
babelOptions: {} // or traceurOptions or typescriptOptions
Copy link

cem2ran commented Dec 28, 2015

You don't even need to have a server running! Just double-click on react.html. Initial load can be slow, but everything should be cached moving on.

Copy link

PAEz commented Dec 30, 2015

Works in plunker aswell..... should work on most of those things, jsbin, fiddle, woteva

This is sweet as guys, thanks heaps!!!
Dont know how jspm works and dont have to care, love it when its like that. So many tools you have to know how to use them to use them, this was nice.

And here it is using mobservable!...., that makes me happy.

I encountered one thing I had to learn for this.
When trying to import mobservable using import mobservable from 'npm:mobservable'; everything was fine, but when trying to import mobservable-react that way it complained it couldnt find mobservable.
This is because in the source for mobservable-react it imports with mobservable and not npm:mobservable like jspm needs.
So to fix that you need to create an alias for it in the map part of you config when you init jspm. You can see how easy it is to do that by looking at the html of the above example.
Hope that helps anyone else looking to use jspm without reading the docs ;P

And heres the bigger mobservable example...
...doing that one really highlighted why jspm is awesome. All mobservables examples are using specific scripts just to get it working online on jsfiddle, some of which is no longer supported. So when I made it use jspm and npm stuff a few things didnt work as they where using outdated stuff, now its using the latest from the npm, so the online stuff is now the same as your local code....nice.

Copy link

This is very convenient, thank you very much. Out of curiosity: Is there a way to use CommonJS here instead of ES2015 modules?

Copy link

cem2ran commented Jan 3, 2016

@frostney, that shouldn't be a problem.

@kolodny: nice! I went a little further:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment