• JSX (optional) • Forces a component based approach (remember directives?) • Server-side rendering (isomorphic apps) • Virtual DOM • Component lifecycle hooks • One way data flow (state, props)
you can do in JS • Minimizes that by working with an in-memory representation of the DOM (virtual) • Computes the minimal amount of changes • Batches updates to DOM • Borrowed concept from the gaming world
re-rendering • State is individual to a component • Props are passed down through component hierarchy • Keep state as high as possible • Pass everything to children via props: data, event handlers, etc. • Smart components are state aware • Dumb components are pure and predictable • Few Smarts, lots of Dumbs • Keep utils, data processing methods, business logic, etc. elsewhere
Pass data down to components via props (handlers included) • XHR calls, event listeners (except Stores subscription) in componentDidMount() • Return null or false when you don’t want to render (cheap because of VDOM; don’t write custom logic or do dynamic component injection yourself) • render() must be pure • Use shouldComponentUpdate() only if you know what you’re doing • Always define types for your props • Make use of defaultProps when needed
render on large component trees • State inside components • Easy to run into “render storms” (coined and derived that from “paint storms” : D) • HTML in JS? (sry Paul, can’t do anything here…)
• It’s not “React specific” but they do complement each other • Proposes a unidirectional data flow model • Event based communication • Dispatcher, Stores, Views, Actions • Much like the human body
flow • A registry of callbacks • It’s dumb • His only purpose is to distribute the actions to the stores (forward logic) • As the application grows, it becomes vital (think custom logic, interceptor-like pattern from angular, manage dependencies and callbacks order, etc.)
objects (domain driven) • Single source of truth for state (component/page/etc.) • Stores register themselves with the dispatcher and provide callbacks for different action types (the ones they are interested in) • After logic is executed, they broadcast an event declaring the state has changed (this impacts the view)
provide the glue code to get data from stores and manage how that data is passed to their children • They listen to the stores’ events • When the event happens, they query the store for new data and re-render themselves (via setState())
forwarded to stores) • Usually wrapped in semantic helper methods, to make them easier to be called from within views • Eg: talkAboutReact(time, place) in a file called ReignActions.js • They also have a type, so they can be filtered out by stores • User interactions trigger actions (eg: button click then fetch new data) • Some actions may come from the server (eg: during initialization)