seiffert / require-jsx

A require.js plugin that allows you to use JSX files as require.js dependencies.
96 stars 17 forks source link

Example one-click project #2

Open jordwalke opened 11 years ago

jordwalke commented 11 years ago

It would be great to have an example one-click project that someone can easily clone. Would you be willing to make this? If possible, it would be cool to see it working with and without the server (completely in-browser) and with or without r.js (if possible.)

samspot commented 10 years ago

I just finished something like this so I'll share:

https://github.com/samspot/react-requirejs-example

ssorallen commented 10 years ago

@samspot your project looks great. How do you feel about writing plain JS (as opposed to JSX) in main.js instead of making CommentBox.js a bootstrapping component? It's not apparent that it renders to the DOM since all other components are just class definitions.

This would replace main.js:22:

require([
  "react",
  "jsx!CommentBox"
], function(React, CommentBox) {
  React.renderComponent(
    CommentBox(null),
    document.getElementById('content')
  );
});

And CommentBox.js would return its class rather than render to the DOM and return nothing.

Edit: The original code was borked. This should now work.

samspot commented 10 years ago

@ssorallen Thanks! I totally agree with this advice. I was stuck because I wasn't sure how to do the basic renderComponent step from within main.js. Didn't occur to me to do it the non-jsx way. I will update the repository.

ssorallen commented 10 years ago

@samspot I just looked at my code and realized how off it was; I wrote it quickly. I updated it to actually be useable.

samspot commented 10 years ago

@ssorallen No problem, I knew what to do. Repo updated :)