Skip to content

Instantly share code, notes, and snippets.

@grahamb
Last active December 2, 2015 00:29
Show Gist options
  • Save grahamb/c1a9fca85a6c4aa061e8 to your computer and use it in GitHub Desktop.
Save grahamb/c1a9fca85a6c4aa061e8 to your computer and use it in GitHub Desktop.
LCP React Lunch and Learn
  • What is react?

  • Why is it nifty?

  • Hello World

// First, we'll render a <div> into the document body
ReactDOM.render(
<div>Hello I am React.</div>,
document.getElementById('example')
);
// Whoa, you put HTML into my JavaScript? Whaaaaaat?
// Fine, we can use plain old JS too.
ReactDOM.render(
React.DOM.div(
{},
'Hello I am also React.'
),
document.getElementById('example')
);
/*
Let's create an actual component now.
A component can be thought of as a function that takes in
props and state, and returns a UI. We'll be returning HTML
using ReactDOM, but you could also be returning the UI for
an iOS or Android app using React Native, or to a <canvas>
using react-canvas.
*/
var HelloWorld = React.createClass({
render: function () {
return (
<p>Hello I am react</p>
);
}
});
ReactDOM.render(<HelloWorld />, document.getElementById('example'));
// ES6 Classes:
// class HelloWorld extends React.Component {
// render() {
// return (
// <p>Hello I am react</p>
// );
// }
}
/*
So far we've just made a pretty dumb component.
All it can do is render out some static text.
Let's fix that.
Let's make a <HelloClock>.
*/
var HelloClock = React.createClass({
render() {
return (
<div>
<p>Hello there. The current time is: ????</p>
</div>
);
}
});
ReactDOM.render(<HelloClock />, document.getElementById('example'));
asdfasdfasdf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment