On Github harishv7 / reactjs
Slides: http://harishv7.github.io/reactjs Materials: http://bit.ly/reactjsmaterials Harish V / @harishv207
Located at AS6-02-09/10/11
It's a UI library.
i.e. It's only the view layer in Model-View-Controller
Simple to learn
Reusable components
Easy to use with existing projects
instagram.com
facebook.com (parts of it)
State changes -> Define and make UI changes yourself (manual)
Listen for changes Add a new todo item Append new item to item list Keep track of which new item was added Use jQuery to update multiple parts of the UI You need to keep track of stateState changes -> UI re-renders based on new state (auto)
Add a new todo item Append new item to item list Update state with new item list with this.setStateUI components are composable and reusable, and can present data that changes over time.
Helps identify which parts have changed by comparing the new version with the previously stored one
Determines how to upload the browser's DOM more efficiently
Properties which can be passed around (even among components)
Models the current app. Used to update the UI.
App, Header, InputField, TodoItemList, TodoItem..
render (compulsory)
getInitialState getDefaultPropscomponentWillMount
componentDidMount
shouldComponentUpdate
componentWillUpdate
componentDidUpdate
e.g. a div containing "Hello world."
var MyApp = React.createClass({ render: function() { return ( // className, not class <div className="main"> Hello world. <div> ); } });
ReactDOM.render(<MyApp>, document.getElementById("todoapp"));
JSX: HTML-like markup
Write UI code in JavaScript!
var MyApp = React.createClass({ render: function() { return ( <div> <ChildComponent> <div> ) } }); var ChildComponent = React.createClass({ render: function() { return ( <div>Hello world.</div> ) } });
var MyApp = React.createClass({ // React method to set default props getDefaultProps: function() { return { name: "Tom" }; }, render: function() { return ( <div> Good morning, {this.props.name} // Create a prop named "text" <ChildComponent text="Hello world" /> </div> ); } }); var ChildComponent = React.createClass({ render: function() { return ( // Get the text prop <div>{this.props.text}</div> ); } });
Flux: An Application Architecture Framework
React Native: Creating rich mobile applications the React way
Post-Workshop Feedback: http://bit.ly/reactjs2016
Resources: Flux GraphQL Relay React Native