I recently stumbled upon facebook's React library, which is a Javascript library for building reusable frontend components. Even if this lib is only at version 0.3.x it behaves very stable, it is fast and is fun to code. I'm a big fan of require.js, so I tried to use React within the require.js eco system. It was not as hard as expected and here are some examples and some thoughts about it.
This is a menu component I use for a twitter bootstrap based project. The eventbus is based on EventEmitter2.
The fact I like most about using require.js together with React is, that you can write a component in one require.js module definition and just export the visible component part. The second advantage is the naming. If you use JSX you can influence the tag names and do some kind of vendor prefixing for your required tags.
In the end, the construction of the menu looks like this:
update:
The way to get things working was quite easy. React is available via Bower, so just add it to your bower.json file:
Afterwards, add it to your require.js config. I decided to change my bower install path to /public/js/components
, my application scripts reside within /public/js/app
.
After settings things up like this, the previously mentioned examples work like a charm.