diff --git a/blog/2013/06/02/jsfiddle-integration.html b/blog/2013/06/02/jsfiddle-integration.html index 79000de039..d22b1262b4 100644 --- a/blog/2013/06/02/jsfiddle-integration.html +++ b/blog/2013/06/02/jsfiddle-integration.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/06/05/why-react.html b/blog/2013/06/05/why-react.html index 6049aa5461..6e282cc930 100644 --- a/blog/2013/06/05/why-react.html +++ b/blog/2013/06/05/why-react.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/06/12/community-roundup.html b/blog/2013/06/12/community-roundup.html index c9957dcb3f..cbe1a610a8 100644 --- a/blog/2013/06/12/community-roundup.html +++ b/blog/2013/06/12/community-roundup.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/06/19/community-roundup-2.html b/blog/2013/06/19/community-roundup-2.html index ab67fffdc5..ccc1f643af 100644 --- a/blog/2013/06/19/community-roundup-2.html +++ b/blog/2013/06/19/community-roundup-2.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/06/21/react-v0-3-3.html b/blog/2013/06/21/react-v0-3-3.html index cdac25735e..0c4d98cf51 100644 --- a/blog/2013/06/21/react-v0-3-3.html +++ b/blog/2013/06/21/react-v0-3-3.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/06/27/community-roundup-3.html b/blog/2013/06/27/community-roundup-3.html index be68911752..039b4f23bd 100644 --- a/blog/2013/06/27/community-roundup-3.html +++ b/blog/2013/06/27/community-roundup-3.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/07/02/react-v0-4-autobind-by-default.html b/blog/2013/07/02/react-v0-4-autobind-by-default.html index 76c63594d9..baac57030e 100644 --- a/blog/2013/07/02/react-v0-4-autobind-by-default.html +++ b/blog/2013/07/02/react-v0-4-autobind-by-default.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/07/03/community-roundup-4.html b/blog/2013/07/03/community-roundup-4.html index bdb7692206..de42fa8bce 100644 --- a/blog/2013/07/03/community-roundup-4.html +++ b/blog/2013/07/03/community-roundup-4.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/07/11/react-v0-4-prop-validation-and-default-values.html b/blog/2013/07/11/react-v0-4-prop-validation-and-default-values.html index 32c9fe289e..725da74e78 100644 --- a/blog/2013/07/11/react-v0-4-prop-validation-and-default-values.html +++ b/blog/2013/07/11/react-v0-4-prop-validation-and-default-values.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/07/17/react-v0-4-0.html b/blog/2013/07/17/react-v0-4-0.html index b2dd0eda2e..9798dfc701 100644 --- a/blog/2013/07/17/react-v0-4-0.html +++ b/blog/2013/07/17/react-v0-4-0.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/07/23/community-roundup-5.html b/blog/2013/07/23/community-roundup-5.html index 5b91762480..dbee7a27a8 100644 --- a/blog/2013/07/23/community-roundup-5.html +++ b/blog/2013/07/23/community-roundup-5.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/07/26/react-v0-4-1.html b/blog/2013/07/26/react-v0-4-1.html index ae4535f3e2..ab48193a04 100644 --- a/blog/2013/07/26/react-v0-4-1.html +++ b/blog/2013/07/26/react-v0-4-1.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/07/30/use-react-and-jsx-in-ruby-on-rails.html b/blog/2013/07/30/use-react-and-jsx-in-ruby-on-rails.html index 47eb3ad642..d08e6c6ca7 100644 --- a/blog/2013/07/30/use-react-and-jsx-in-ruby-on-rails.html +++ b/blog/2013/07/30/use-react-and-jsx-in-ruby-on-rails.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/08/05/community-roundup-6.html b/blog/2013/08/05/community-roundup-6.html index 9dae0419db..4b19a103ca 100644 --- a/blog/2013/08/05/community-roundup-6.html +++ b/blog/2013/08/05/community-roundup-6.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/08/19/use-react-and-jsx-in-python-applications.html b/blog/2013/08/19/use-react-and-jsx-in-python-applications.html index aa55c1bd8c..190b164282 100644 --- a/blog/2013/08/19/use-react-and-jsx-in-python-applications.html +++ b/blog/2013/08/19/use-react-and-jsx-in-python-applications.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/08/26/community-roundup-7.html b/blog/2013/08/26/community-roundup-7.html index 35bf8a3ed9..80e0460eb8 100644 --- a/blog/2013/08/26/community-roundup-7.html +++ b/blog/2013/08/26/community-roundup-7.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/09/24/community-roundup-8.html b/blog/2013/09/24/community-roundup-8.html index 6bfacc4a62..08bc49f15f 100644 --- a/blog/2013/09/24/community-roundup-8.html +++ b/blog/2013/09/24/community-roundup-8.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/10/03/community-roundup-9.html b/blog/2013/10/03/community-roundup-9.html index 98ed419a6a..1e92b2fb38 100644 --- a/blog/2013/10/03/community-roundup-9.html +++ b/blog/2013/10/03/community-roundup-9.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/10/16/react-v0.5.0.html b/blog/2013/10/16/react-v0.5.0.html index 671057ad79..c376ccdd78 100644 --- a/blog/2013/10/16/react-v0.5.0.html +++ b/blog/2013/10/16/react-v0.5.0.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/10/29/react-v0-5-1.html b/blog/2013/10/29/react-v0-5-1.html index b28e1f2671..c24a66aa92 100644 --- a/blog/2013/10/29/react-v0-5-1.html +++ b/blog/2013/10/29/react-v0-5-1.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/11/05/thinking-in-react.html b/blog/2013/11/05/thinking-in-react.html index 9de8dd4889..8e3c0c2f45 100644 --- a/blog/2013/11/05/thinking-in-react.html +++ b/blog/2013/11/05/thinking-in-react.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/11/06/community-roundup-10.html b/blog/2013/11/06/community-roundup-10.html index 8da737b8f5..61f2d30772 100644 --- a/blog/2013/11/06/community-roundup-10.html +++ b/blog/2013/11/06/community-roundup-10.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/11/18/community-roundup-11.html b/blog/2013/11/18/community-roundup-11.html index 9699996819..0795112820 100644 --- a/blog/2013/11/18/community-roundup-11.html +++ b/blog/2013/11/18/community-roundup-11.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/12/18/react-v0.5.2-v0.4.2.html b/blog/2013/12/18/react-v0.5.2-v0.4.2.html index 28ebe0715f..bd921fd3cd 100644 --- a/blog/2013/12/18/react-v0.5.2-v0.4.2.html +++ b/blog/2013/12/18/react-v0.5.2-v0.4.2.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/12/19/react-v0.8.0.html b/blog/2013/12/19/react-v0.8.0.html index 0054686a85..d8994ee42b 100644 --- a/blog/2013/12/19/react-v0.8.0.html +++ b/blog/2013/12/19/react-v0.8.0.html @@ -58,6 +58,8 @@

Recent posts

diff --git a/blog/2013/12/23/community-roundup-12.html b/blog/2013/12/23/community-roundup-12.html new file mode 100644 index 0000000000..e9fd14f286 --- /dev/null +++ b/blog/2013/12/23/community-roundup-12.html @@ -0,0 +1,201 @@ + + + + + + React | Community Round-up #12 + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+ + +
+

Community Round-up #12

+

December 23, 2013 by Vjeux

+ +
+ +
+

React got featured on the front-page of Hacker News thanks to the Om library. If you try it out for the first time, take a look at the docs and do not hesitate to ask questions on the Google Group, IRC or Stack Overflow. We are trying our best to help you out!

+

The Future of Javascript MVC #

+

David Nolan announced Om, a thin wrapper on-top of React in ClojureScript. It stands out by only using immutable data structures. This unlocks the ability to write a very efficient shouldComponentUpdate and get huge performance improvements on some tasks.

+ +
+

We've known this for some time over here in the ClojureScript corner of the world - all of our collections are immutable and modeled directly on the original Clojure versions written in Java. Modern JavaScript engines have now been tuned to the point that it's no longer uncommon to see collection performance within 2.5X of the Java Virtual Machine.

+ +

Wait, wait, wait. What does the performance of persistent data structures have to do with the future of JavaScript MVCs?

+ +

A whole lot. +

+ +

Read the full article...

+
+

Scroll Position with React #

+

Managing the scroll position when new content is inserted is usually very tricky to get right. Vjeux discovered that componentWillUpdate and componentDidUpdate were triggered exactly at the right time to manage the scroll position.

+ +
+

We can check the scroll position before the component has updated with componentWillUpdate and scroll if necessary at componentDidUpdate

+
componentWillUpdate: function() {
+  var node = this.getDOMNode();
+  this.shouldScrollBottom =
+    (node.scrollTop + node.offsetHeight) === node.scrollHeight;
+},
+componentDidUpdate: function() {
+  if (this.shouldScrollBottom) {
+    var node = this.getDOMNode();
+    node.scrollTop = node.scrollHeight
+  }
+},
+
+

Check out the blog article...

+
+

Lights Out #

+

React declarative approach is well suited to write games. Cheng Lou wrote the famous Lights Out game in React. It's a good example of use of TransitionGroup to implement animations. +

+ +

Try it out!

+

Reactive Table Bookmarklet #

+

Stoyan Stefanov wrote a bookmarklet to process tables on the internet. It adds a little "pop" button that expands to a full-screen view with sorting, editing and export to csv and json. +

+ +

Check out the blog post...

+

MontageJS Tutorial in React #

+

Ross Allen implemented MontageJS's Reddit tutorial in React. This is a good opportunity to compare the philosophies of the two libraries.

+ + + +

View the source on JSFiddle...

+

Writing Good React Components #

+

William Högman Rudenmalm wrote an article on how to write good React components. This is full of good advice.

+ +
+

The idea of dividing software into smaller parts or components is hardly new - It is the essance of good software. The same principles that apply to software in general apply to building React components. That doesn’t mean that writing good React components is just about applying general rules.

+ +

The web offers a unique set of challenges, which React offers interesting solutions to. First and foremost among these solutions is the what is called the Mock DOM. Rather than having user code interface with the DOM in a direct fashion, as is the case with most DOM manipulation libraries.

+ +

You build a model of how you want the DOM end up like. React then inserts this model into the DOM. This is very useful for updates because React simply compares the model or mock DOM against the actual DOM, and then only updates based on the difference between the two states.

+ +

Read the full article ...

+
+

Hoodie React TodoMVC #

+

Sven Lito integrated the React TodoMVC example within an Hoodie web app environment. This should let you get started using Hoodie and React.

+
hoodie new todomvc -t "hoodiehq/hoodie-react-todomvc"
+
+

Check out on GitHub...

+

JSX Compiler #

+

Ever wanted to have a quick way to see what a JSX tag would be converted to? Tim Yung made a page for it. +

+ +

Try it out!

+

Random Tweet #

+

+ +
+ +
+
+
+
+ + + +
+
+ + + + diff --git a/blog/all.html b/blog/all.html index deca1d584a..8efcac7144 100644 --- a/blog/all.html +++ b/blog/all.html @@ -56,6 +56,8 @@

All Posts

+

Community Round-up #12 on December 23, 2013 by Vjeux

+

React v0.8 on December 19, 2013 by Paul O'Shannessy

React v0.5.2, v0.4.2 on December 18, 2013 by Paul O'Shannessy

diff --git a/blog/index.html b/blog/index.html index a2692c98c4..b6de3dd81e 100644 --- a/blog/index.html +++ b/blog/index.html @@ -58,6 +58,8 @@

Recent posts

@@ -85,6 +85,88 @@
+
+

Community Round-up #12

+

December 23, 2013 by Vjeux

+
+
+

React got featured on the front-page of Hacker News thanks to the Om library. If you try it out for the first time, take a look at the docs and do not hesitate to ask questions on the Google Group, IRC or Stack Overflow. We are trying our best to help you out!

+

The Future of Javascript MVC #

+

David Nolan announced Om, a thin wrapper on-top of React in ClojureScript. It stands out by only using immutable data structures. This unlocks the ability to write a very efficient shouldComponentUpdate and get huge performance improvements on some tasks.

+ +
+

We've known this for some time over here in the ClojureScript corner of the world - all of our collections are immutable and modeled directly on the original Clojure versions written in Java. Modern JavaScript engines have now been tuned to the point that it's no longer uncommon to see collection performance within 2.5X of the Java Virtual Machine.

+ +

Wait, wait, wait. What does the performance of persistent data structures have to do with the future of JavaScript MVCs?

+ +

A whole lot. +

+ +

Read the full article...

+
+

Scroll Position with React #

+

Managing the scroll position when new content is inserted is usually very tricky to get right. Vjeux discovered that componentWillUpdate and componentDidUpdate were triggered exactly at the right time to manage the scroll position.

+ +
+

We can check the scroll position before the component has updated with componentWillUpdate and scroll if necessary at componentDidUpdate

+
componentWillUpdate: function() {
+  var node = this.getDOMNode();
+  this.shouldScrollBottom =
+    (node.scrollTop + node.offsetHeight) === node.scrollHeight;
+},
+componentDidUpdate: function() {
+  if (this.shouldScrollBottom) {
+    var node = this.getDOMNode();
+    node.scrollTop = node.scrollHeight
+  }
+},
+
+

Check out the blog article...

+
+

Lights Out #

+

React declarative approach is well suited to write games. Cheng Lou wrote the famous Lights Out game in React. It's a good example of use of TransitionGroup to implement animations. +

+ +

Try it out!

+

Reactive Table Bookmarklet #

+

Stoyan Stefanov wrote a bookmarklet to process tables on the internet. It adds a little "pop" button that expands to a full-screen view with sorting, editing and export to csv and json. +

+ +

Check out the blog post...

+

MontageJS Tutorial in React #

+

Ross Allen implemented MontageJS's Reddit tutorial in React. This is a good opportunity to compare the philosophies of the two libraries.

+ + + +

View the source on JSFiddle...

+

Writing Good React Components #

+

William Högman Rudenmalm wrote an article on how to write good React components. This is full of good advice.

+ +
+

The idea of dividing software into smaller parts or components is hardly new - It is the essance of good software. The same principles that apply to software in general apply to building React components. That doesn’t mean that writing good React components is just about applying general rules.

+ +

The web offers a unique set of challenges, which React offers interesting solutions to. First and foremost among these solutions is the what is called the Mock DOM. Rather than having user code interface with the DOM in a direct fashion, as is the case with most DOM manipulation libraries.

+ +

You build a model of how you want the DOM end up like. React then inserts this model into the DOM. This is very useful for updates because React simply compares the model or mock DOM against the actual DOM, and then only updates based on the difference between the two states.

+ +

Read the full article ...

+
+

Hoodie React TodoMVC #

+

Sven Lito integrated the React TodoMVC example within an Hoodie web app environment. This should let you get started using Hoodie and React.

+
hoodie new todomvc -t "hoodiehq/hoodie-react-todomvc"
+
+

Check out on GitHub...

+

JSX Compiler #

+

Ever wanted to have a quick way to see what a JSX tag would be converted to? Tim Yung made a page for it. +

+ +

Try it out!

+

Random Tweet #

+

+ +
+
+

React v0.8

December 19, 2013 by Paul O'Shannessy

@@ -350,153 +432,6 @@ Is this some sort of template language? Specifically no. This might have been th
-
-

Thinking in React

-

November 5, 2013 by Pete Hunt

-
-
-

React is, in my opinion, the premier way to build big, fast Web apps with JavaScript. It's scaled very well for us at Facebook and Instagram.

- -

One of the many great parts of React is how it makes you think about apps as you build them. In this post I'll walk you through the thought process of building a searchable product data table using React.

-

Start with a mock #

-

Imagine that we already have a JSON API and a mock from our designer. Our designer apparently isn't very good because the mock looks like this:

- -

Mockup

- -

Our JSON API returns some data that looks like this:

-
[
-  {category: "Sporting Goods", price: "$49.99", stocked: true, name: "Football"},
-  {category: "Sporting Goods", price: "$9.99", stocked: true, name: "Baseball"},
-  {category: "Sporting Goods", price: "$29.99", stocked: false, name: "Basketball"},
-  {category: "Electronics", price: "$99.99", stocked: true, name: "iPod Touch"},
-  {category: "Electronics", price: "$399.99", stocked: false, name: "iPhone 5"},
-  {category: "Electronics", price: "$199.99", stocked: true, name: "Nexus 7"}
-];
-

Step 1: break the UI into a component hierarchy #

-

The first thing you'll want to do is to draw boxes around every component (and subcomponent) in the mock and give them all names. If you're working with a designer they may have already done this, so go talk to them! Their Photoshop layer names may end up being the names of your React components!

- -

But how do you know what should be its own component? Just use the same techniques for deciding if you should create a new function or object. One such technique is the single responsibility principle, that is, a component should ideally only do one thing. If it ends up growing it should be decomposed into smaller subcomponents.

- -

Since you're often displaying a JSON data model to a user, you'll find that if your model was built correctly your UI (and therefore your component structure) will map nicely onto it. That's because user interfaces and data models tend to adhere to the same information architecture which means the work of separating your UI into components is often trivial. Just break it up into components that represent exactly one piece of your data model.

- -

Component diagram

- -

You'll see here that we have five components in our simple app. I've italicized the data each component represents.

- -
    -
  1. FilterableProductTable (orange): contains the entirety of the example
  2. -
  3. SearchBar (blue): receives all user input
  4. -
  5. ProductTable (green): displays and filters the data collection based on user input
  6. -
  7. ProductCategoryRow (turquoise): displays a heading for each category
  8. -
  9. ProductRow (red): displays a row for each product
  10. -
- -

If you look at ProductTable you'll see that the table header (containing the "Name" and "Price" labels) isn't its own component. This is a matter of preference and there's an argument to be made either way. For this example I left it as part of ProductTable because it is part of rendering the data collection which is ProductTable's responsibility. However if this header grows to be complex (i.e. if we were to add affordances for sorting) it would certainly make sense to make this its own ProductTableHeader component.

- -

Now that we've identified the components in our mock, let's arrange them into a hierarchy. This is easy. Components that appear within another component in the mock should appear as a child in the hierarchy:

- - -

Step 2: Build a static version in React #

- - -

Now that you have your component hierarchy it's time to start implementing your app. The easiest way is to build a version that takes your data model and renders the UI but has no interactivity. It's easiest to decouple these processes because building building a static version requires a lot of typing and no thinking, and adding interactivity requires a lot of thinking and not a lot of typing. We'll see why.

- -

To build a static version of your app that renders your data model you'll want to build components that reuse other components and pass data using props. props are a way of passing data from parent to child. If you're familiar with the concept of state, don't use state at all to build this static version. State is reserved only for interactivity, that is, data that changes over time. Since this is a static version of the app you don't need it.

- -

You can build top-down or bottom-up. That is, you can either start with building the components higher up in the hierarchy (i.e. starting with FilterableProductTable) or with the ones lower in it (ProductRow). In simpler examples it's usually easier to go top-down and on larger projects it's easier to go bottom-up and write tests as you build.

- -

At the end of this step you'll have a library of reusable components that render your data model. The components will only have render() methods since this is a static version of your app. The component at the top of the hierarchy (FilterableProductTable) will take your data model as a prop. If you make a change to your underlying data model and call renderComponent() again the UI will be updated. It's easy to see how your UI is updated and where to make changes since there's nothing complicated going on since React's one-way data flow (also called one-way binding) keeps everything modular, easy to reason about, and fast.

- -

Simply refer to the React docs if you need help executing this step.

-

A brief interlude: props vs state #

-

There are two types of "model" data in React: props and state. It's important to understand the distinction between the two; skim the official React docs if you aren't sure what the difference is.

-

Step 3: Identify the minimal (but complete) representation of UI state #

-

To make your UI interactive you need to be able to trigger changes to your underlying data model. React makes this easy with state.

- -

To build your app correctly you first need to think of the minimal set of mutable state that your app needs. The key here is DRY: Don't Repeat Yourself. Figure out what the absolute minimal representation of the state of your application needs to be and compute everything else you need on-demand. For example, if you're building a TODO list, just keep an array of the TODO items around; don't keep a separate state variable for the count. Instead, when you want to render the TODO count simply take the length of the TODO items array.

- -

Think of all of the pieces of data in our example application. We have:

- - - -

Let's go through each one and figure out which one is state. Simply ask three questions about each piece of data:

- -
    -
  1. Is it passed in from a parent via props? If so, it probably isn't state.
  2. -
  3. Does it change over time? If not, it probably isn't state.
  4. -
  5. Can you compute it based on any other state or props in your component? If so, it's not state.
  6. -
- -

The original list of products is passed in as props, so that's not state. The search text and the checkbox seem to be state since they change over time and can't be computed from anything. And finally, the filtered list of products isn't state because it can be computed by combining the original list of products with the search text and value of the checkbox.

- -

So finally, our state is:

- - -

Step 4: Identify where your state should live #

- - -

OK, so we've identified what the minimal set of app state is. Next we need to identify which component mutates, or owns, this state.

- -

Remember: React is all about one-way data flow down the component hierarchy. It may not be immediately clear which component should own what state. This is often the most challenging part for newcomers to understand, so follow these steps to figure it out:

- -

For each piece of state in your application:

- - - -

Let's run through this strategy for our application:

- - - -

Cool, so we've decided that our state lives in FilterableProductTable. First, add a getInitialState() method to FilterableProductTable that returns {filterText: '', inStockOnly: false} to reflect the initial state of your application. Then pass filterText and inStockOnly to ProductTable and SearchBar as a prop. Finally, use these props to filter the rows in ProductTable and set the values of the form fields in SearchBar.

- -

You can start seeing how your application will behave: set filterText to "ball" and refresh your app. You'll see the data table is updated correctly.

-

Step 5: Add inverse data flow #

- - -

So far we've built an app that renders correctly as a function of props and state flowing down the hierarchy. Now it's time to support data flowing the other way: the form components deep in the hierarchy need to update the state in FilterableProductTable.

- -

React makes this data flow explicit to make it easy to understand how your program works, but it does require a little more typing than traditional two-way data binding. React provides an add-on called ReactLink to make this pattern as convenient as two-way binding, but for the purpose of this post we'll keep everything explicit.

- -

If you try to type or check the box in the current version of the example you'll see that React ignores your input. This is intentional, as we've set the value prop of the input to always be equal to the state passed in from FilterableProductTable.

- -

Let's think about what we want to happen. We want to make sure that whenever the user changes the form we update the state to reflect the user input. Since components should only update their own state, FilterableProductTable will pass a callback to SearchBar that will fire whenever the state should be updated. We can use the onChange event on the inputs to be notified of it. And the callback passed by FilterableProductTable will call setState() and the app will be updated.

- -

Though this sounds like a lot it's really just a few lines of code. And it's really explicit how your data is flowing throughout the app.

-

And that's it #

-

Hopefully this gives you an idea of how to think about building components and applications with React. While it may be a little more typing than you're used to, remember that code is read far more than it's written, and it's extremely easy to read this modular, explicit code. As you start to build large libraries of components you'll appreciate this explicitness and modularity, and with code reuse your lines of code will start to shrink :)

- -
-
- @@ -85,6 +85,153 @@
+
+

Thinking in React

+

November 5, 2013 by Pete Hunt

+
+
+

React is, in my opinion, the premier way to build big, fast Web apps with JavaScript. It's scaled very well for us at Facebook and Instagram.

+ +

One of the many great parts of React is how it makes you think about apps as you build them. In this post I'll walk you through the thought process of building a searchable product data table using React.

+

Start with a mock #

+

Imagine that we already have a JSON API and a mock from our designer. Our designer apparently isn't very good because the mock looks like this:

+ +

Mockup

+ +

Our JSON API returns some data that looks like this:

+
[
+  {category: "Sporting Goods", price: "$49.99", stocked: true, name: "Football"},
+  {category: "Sporting Goods", price: "$9.99", stocked: true, name: "Baseball"},
+  {category: "Sporting Goods", price: "$29.99", stocked: false, name: "Basketball"},
+  {category: "Electronics", price: "$99.99", stocked: true, name: "iPod Touch"},
+  {category: "Electronics", price: "$399.99", stocked: false, name: "iPhone 5"},
+  {category: "Electronics", price: "$199.99", stocked: true, name: "Nexus 7"}
+];
+

Step 1: break the UI into a component hierarchy #

+

The first thing you'll want to do is to draw boxes around every component (and subcomponent) in the mock and give them all names. If you're working with a designer they may have already done this, so go talk to them! Their Photoshop layer names may end up being the names of your React components!

+ +

But how do you know what should be its own component? Just use the same techniques for deciding if you should create a new function or object. One such technique is the single responsibility principle, that is, a component should ideally only do one thing. If it ends up growing it should be decomposed into smaller subcomponents.

+ +

Since you're often displaying a JSON data model to a user, you'll find that if your model was built correctly your UI (and therefore your component structure) will map nicely onto it. That's because user interfaces and data models tend to adhere to the same information architecture which means the work of separating your UI into components is often trivial. Just break it up into components that represent exactly one piece of your data model.

+ +

Component diagram

+ +

You'll see here that we have five components in our simple app. I've italicized the data each component represents.

+ +
    +
  1. FilterableProductTable (orange): contains the entirety of the example
  2. +
  3. SearchBar (blue): receives all user input
  4. +
  5. ProductTable (green): displays and filters the data collection based on user input
  6. +
  7. ProductCategoryRow (turquoise): displays a heading for each category
  8. +
  9. ProductRow (red): displays a row for each product
  10. +
+ +

If you look at ProductTable you'll see that the table header (containing the "Name" and "Price" labels) isn't its own component. This is a matter of preference and there's an argument to be made either way. For this example I left it as part of ProductTable because it is part of rendering the data collection which is ProductTable's responsibility. However if this header grows to be complex (i.e. if we were to add affordances for sorting) it would certainly make sense to make this its own ProductTableHeader component.

+ +

Now that we've identified the components in our mock, let's arrange them into a hierarchy. This is easy. Components that appear within another component in the mock should appear as a child in the hierarchy:

+ +
    +
  • FilterableProductTable + +
      +
    • SearchBar
    • +
    • ProductTable + +
        +
      • ProductCategoryRow
      • +
      • ProductRow
      • +
    • +
  • +
+

Step 2: Build a static version in React #

+ + +

Now that you have your component hierarchy it's time to start implementing your app. The easiest way is to build a version that takes your data model and renders the UI but has no interactivity. It's easiest to decouple these processes because building building a static version requires a lot of typing and no thinking, and adding interactivity requires a lot of thinking and not a lot of typing. We'll see why.

+ +

To build a static version of your app that renders your data model you'll want to build components that reuse other components and pass data using props. props are a way of passing data from parent to child. If you're familiar with the concept of state, don't use state at all to build this static version. State is reserved only for interactivity, that is, data that changes over time. Since this is a static version of the app you don't need it.

+ +

You can build top-down or bottom-up. That is, you can either start with building the components higher up in the hierarchy (i.e. starting with FilterableProductTable) or with the ones lower in it (ProductRow). In simpler examples it's usually easier to go top-down and on larger projects it's easier to go bottom-up and write tests as you build.

+ +

At the end of this step you'll have a library of reusable components that render your data model. The components will only have render() methods since this is a static version of your app. The component at the top of the hierarchy (FilterableProductTable) will take your data model as a prop. If you make a change to your underlying data model and call renderComponent() again the UI will be updated. It's easy to see how your UI is updated and where to make changes since there's nothing complicated going on since React's one-way data flow (also called one-way binding) keeps everything modular, easy to reason about, and fast.

+ +

Simply refer to the React docs if you need help executing this step.

+

A brief interlude: props vs state #

+

There are two types of "model" data in React: props and state. It's important to understand the distinction between the two; skim the official React docs if you aren't sure what the difference is.

+

Step 3: Identify the minimal (but complete) representation of UI state #

+

To make your UI interactive you need to be able to trigger changes to your underlying data model. React makes this easy with state.

+ +

To build your app correctly you first need to think of the minimal set of mutable state that your app needs. The key here is DRY: Don't Repeat Yourself. Figure out what the absolute minimal representation of the state of your application needs to be and compute everything else you need on-demand. For example, if you're building a TODO list, just keep an array of the TODO items around; don't keep a separate state variable for the count. Instead, when you want to render the TODO count simply take the length of the TODO items array.

+ +

Think of all of the pieces of data in our example application. We have:

+ +
    +
  • The original list of products
  • +
  • The search text the user has entered
  • +
  • The value of the checkbox
  • +
  • The filtered list of products
  • +
+ +

Let's go through each one and figure out which one is state. Simply ask three questions about each piece of data:

+ +
    +
  1. Is it passed in from a parent via props? If so, it probably isn't state.
  2. +
  3. Does it change over time? If not, it probably isn't state.
  4. +
  5. Can you compute it based on any other state or props in your component? If so, it's not state.
  6. +
+ +

The original list of products is passed in as props, so that's not state. The search text and the checkbox seem to be state since they change over time and can't be computed from anything. And finally, the filtered list of products isn't state because it can be computed by combining the original list of products with the search text and value of the checkbox.

+ +

So finally, our state is:

+ +
    +
  • The search text the user has entered
  • +
  • The value of the checkbox
  • +
+

Step 4: Identify where your state should live #

+ + +

OK, so we've identified what the minimal set of app state is. Next we need to identify which component mutates, or owns, this state.

+ +

Remember: React is all about one-way data flow down the component hierarchy. It may not be immediately clear which component should own what state. This is often the most challenging part for newcomers to understand, so follow these steps to figure it out:

+ +

For each piece of state in your application:

+ +
    +
  • Identify every component that renders something based on that state.
  • +
  • Find a common owner component (a single component above all the components that need the state in the hierarchy).
  • +
  • Either the common owner or another component higher up in the hierarchy should own the state.
  • +
  • If you can't find a component where it makes sense to own the state, create a new component simply for holding the state and add it somewhere in the hierarchy above the common owner component.
  • +
+ +

Let's run through this strategy for our application:

+ +
    +
  • ProductTable needs to filter the product list based on state and SearchBar needs to display the search text and checked state.
  • +
  • The common owner component is FilterableProductTable.
  • +
  • It conceptually makes sense for the filter text and checked value to live in FilterableProductTable
  • +
+ +

Cool, so we've decided that our state lives in FilterableProductTable. First, add a getInitialState() method to FilterableProductTable that returns {filterText: '', inStockOnly: false} to reflect the initial state of your application. Then pass filterText and inStockOnly to ProductTable and SearchBar as a prop. Finally, use these props to filter the rows in ProductTable and set the values of the form fields in SearchBar.

+ +

You can start seeing how your application will behave: set filterText to "ball" and refresh your app. You'll see the data table is updated correctly.

+

Step 5: Add inverse data flow #

+ + +

So far we've built an app that renders correctly as a function of props and state flowing down the hierarchy. Now it's time to support data flowing the other way: the form components deep in the hierarchy need to update the state in FilterableProductTable.

+ +

React makes this data flow explicit to make it easy to understand how your program works, but it does require a little more typing than traditional two-way data binding. React provides an add-on called ReactLink to make this pattern as convenient as two-way binding, but for the purpose of this post we'll keep everything explicit.

+ +

If you try to type or check the box in the current version of the example you'll see that React ignores your input. This is intentional, as we've set the value prop of the input to always be equal to the state passed in from FilterableProductTable.

+ +

Let's think about what we want to happen. We want to make sure that whenever the user changes the form we update the state to reflect the user input. Since components should only update their own state, FilterableProductTable will pass a callback to SearchBar that will fire whenever the state should be updated. We can use the onChange event on the inputs to be notified of it. And the callback passed by FilterableProductTable will call setState() and the app will be updated.

+ +

Though this sounds like a lot it's really just a few lines of code. And it's really explicit how your data is flowing throughout the app.

+

And that's it #

+

Hopefully this gives you an idea of how to think about building components and applications with React. While it may be a little more typing than you're used to, remember that code is read far more than it's written, and it's extremely easy to read this modular, explicit code. As you start to build large libraries of components you'll appreciate this explicitness and modularity, and with code reuse your lines of code will start to shrink :)

+ +
+
+

React v0.5.1

October 29, 2013 by Paul O'Shannessy

@@ -304,88 +451,6 @@
-
-

Community Round-up #7

-

August 26, 2013 by Vjeux

-
-
-

It's been three months since we open sourced React and it is going well. Some stats so far:

- - -

Wolfenstein Rendering Engine Ported to React #

-

Pete Hunt ported the render code of the web version of Wolfenstein 3D to React. Check out the demo and render.js file for the implementation. -

-

React & Meteor #

-

Ben Newman made a 13-lines wrapper to use React and Meteor together. Meteor handles the real-time data synchronization between client and server. React provides the declarative way to write the interface and only updates the parts of the UI that changed.

- -
-

This repository defines a Meteor package that automatically integrates the React rendering framework on both the client and the server, to complement or replace the default Handlebars templating system.

- -

The React core is officially agnostic about how you fetch and update your data, so it is far from obvious which approach is the best. This package provides one answer to that question (use Meteor!), and I hope you will find it a compelling combination.

-
var MyComponent = React.createClass({
- mixins: [MeteorMixin],
-
- getMeteorState: function() {
-   return { foo: Session.get('foo') };
- },
-
- render: function() {
-   return <div>{this.state.foo}</div>;
- }
-});
-
-

Dependencies will be registered for any data accesses performed by getMeteorState so that the component can be automatically re-rendered whenever the data changes.

- -

Read more ...

-
-

React Page #

-

Jordan Walke implemented a complete React project creator called react-page. It supports both server-side and client-side rendering, source transform and packaging JSX files using CommonJS modules, and instant reload.

- -
-

Easy Application Development with React JavaScript -

- -

Why Server Rendering?

- -
    -
  • Faster initial page speed: - -
      -
    • Markup displayed before downloading large JavaScript.
    • -
    • Markup can be generated more quickly on a fast server than low power client devices.
    • -
  • -
  • Faster Development and Prototyping: - -
      -
    • Instantly refresh your app without waiting for any watch scripts or bundlers.
    • -
  • -
  • Easy deployment of static content pages/blogs: just archive using recursive wget.
  • -
  • SEO benefits of indexability and perf.
  • -
- -

How Does Server Rendering Work?

- -
    -
  • react-page computes page markup on the server, sends it to the client so the user can see it quickly.
  • -
  • The corresponding JavaScript is then packaged and sent.
  • -
  • The browser runs that JavaScript, so that all of the event handlers, interactions and update code will run seamlessly on top of the server generated markup.
  • -
  • From the developer's (and the user's) perspective, it's just as if the rendering occurred on the client, only faster.
  • -
- -

Try it out ...

-
- -
-
- @@ -85,6 +85,88 @@
+
+

Community Round-up #7

+

August 26, 2013 by Vjeux

+
+
+

It's been three months since we open sourced React and it is going well. Some stats so far:

+ + +

Wolfenstein Rendering Engine Ported to React #

+

Pete Hunt ported the render code of the web version of Wolfenstein 3D to React. Check out the demo and render.js file for the implementation. +

+

React & Meteor #

+

Ben Newman made a 13-lines wrapper to use React and Meteor together. Meteor handles the real-time data synchronization between client and server. React provides the declarative way to write the interface and only updates the parts of the UI that changed.

+ +
+

This repository defines a Meteor package that automatically integrates the React rendering framework on both the client and the server, to complement or replace the default Handlebars templating system.

+ +

The React core is officially agnostic about how you fetch and update your data, so it is far from obvious which approach is the best. This package provides one answer to that question (use Meteor!), and I hope you will find it a compelling combination.

+
var MyComponent = React.createClass({
+ mixins: [MeteorMixin],
+
+ getMeteorState: function() {
+   return { foo: Session.get('foo') };
+ },
+
+ render: function() {
+   return <div>{this.state.foo}</div>;
+ }
+});
+
+

Dependencies will be registered for any data accesses performed by getMeteorState so that the component can be automatically re-rendered whenever the data changes.

+ +

Read more ...

+
+

React Page #

+

Jordan Walke implemented a complete React project creator called react-page. It supports both server-side and client-side rendering, source transform and packaging JSX files using CommonJS modules, and instant reload.

+ +
+

Easy Application Development with React JavaScript +

+ +

Why Server Rendering?

+ +
    +
  • Faster initial page speed: + +
      +
    • Markup displayed before downloading large JavaScript.
    • +
    • Markup can be generated more quickly on a fast server than low power client devices.
    • +
  • +
  • Faster Development and Prototyping: + +
      +
    • Instantly refresh your app without waiting for any watch scripts or bundlers.
    • +
  • +
  • Easy deployment of static content pages/blogs: just archive using recursive wget.
  • +
  • SEO benefits of indexability and perf.
  • +
+ +

How Does Server Rendering Work?

+ +
    +
  • react-page computes page markup on the server, sends it to the client so the user can see it quickly.
  • +
  • The corresponding JavaScript is then packaged and sent.
  • +
  • The browser runs that JavaScript, so that all of the event handlers, interactions and update code will run seamlessly on top of the server generated markup.
  • +
  • From the developer's (and the user's) perspective, it's just as if the rendering occurred on the client, only faster.
  • +
+ +

Try it out ...

+
+ +
+
+

Use React and JSX in Python Applications

August 19, 2013 by Kunal Mehta

@@ -261,104 +343,6 @@
-
-

Community Round-up #5

-

July 23, 2013 by Vjeux

-
-
-

We launched the React Facebook Page along with the React v0.4 launch. 700 people already liked it to get updated on the project :)

-

Cross-browser onChange #

-

Ben Alpert from Khan Academy worked on a cross-browser implementation of onChange event that landed in v0.4. He wrote a blog post explaining the various browser quirks he had to deal with.

- -
-

First off, what is the input event? If you have an <input> element and want to receive events whenever the value changes, the most obvious thing to do is to listen to the change event. Unfortunately, change fires only after the text field is defocused, rather than on each keystroke. The next obvious choice is the keyup event, which is triggered whenever a key is released. Unfortunately, keyup doesn't catch input that doesn't involve the keyboard (e.g., pasting from the clipboard using the mouse) and only fires once if a key is held down, rather than once per inserted character.

- -

Both keydown and keypress do fire repeatedly when a key is held down, but both fire immediately before the value changes, so to read the new value you have to defer the handler to the next event loop using setTimeout(fn, 0) or similar, which slows down your app. Of course, like keyup, neither keydown nor keypress fires for non-keyboard input events, and all three can fire in cases where the value doesn't change at all (such as when pressing the arrow keys).

- -

Read the full post...

-
-

React Samples #

-

Learning a new library is always easier when you have working examples you can play with. jwh put many of them on his react-samples Github repo.

- -
-

Some simple examples with Facebook's React framework

- - -
-

React Chosen Wrapper #

-

Cheng Lou wrote a wrapper for the Chosen input library called react-chosen. It took just 25 lines to be able to use jQuery component as a React one.

-
React.renderComponent(
-  <Chosen noResultsText="No result" value="Harvest" onChange={doSomething}>
-    <option value="Facebook">Facebook</option>
-    <option value="Harvest">Harvest</option>
-  </Chosen>
-, document.body);
-

JSX and ES6 Template Strings #

-

Domenic Denicola wrote a slide deck about the great applications of ES6 features and one slide shows how we could use Template Strings to compile JSX at run-time without the need for a pre-processing phase.

- -
-

React Presentation #

-

Tom Occhino and Jordan Walke, React developers, did a presentation of React at Facebook Seattle's office. Check out the first 25 minutes for the presentation and the remaining 45 for a Q&A. I highly recommend you watching this video.

- -
-

Docs #

-

Pete Hunt rewrote the entirety of the docs for v0.4. The goal was to add more explanation about why we built React and what the best practices are.

- -
-

Guides

- - -
- -
-
- @@ -85,6 +85,104 @@
+
+

Community Round-up #5

+

July 23, 2013 by Vjeux

+
+
+

We launched the React Facebook Page along with the React v0.4 launch. 700 people already liked it to get updated on the project :)

+

Cross-browser onChange #

+

Ben Alpert from Khan Academy worked on a cross-browser implementation of onChange event that landed in v0.4. He wrote a blog post explaining the various browser quirks he had to deal with.

+ +
+

First off, what is the input event? If you have an <input> element and want to receive events whenever the value changes, the most obvious thing to do is to listen to the change event. Unfortunately, change fires only after the text field is defocused, rather than on each keystroke. The next obvious choice is the keyup event, which is triggered whenever a key is released. Unfortunately, keyup doesn't catch input that doesn't involve the keyboard (e.g., pasting from the clipboard using the mouse) and only fires once if a key is held down, rather than once per inserted character.

+ +

Both keydown and keypress do fire repeatedly when a key is held down, but both fire immediately before the value changes, so to read the new value you have to defer the handler to the next event loop using setTimeout(fn, 0) or similar, which slows down your app. Of course, like keyup, neither keydown nor keypress fires for non-keyboard input events, and all three can fire in cases where the value doesn't change at all (such as when pressing the arrow keys).

+ +

Read the full post...

+
+

React Samples #

+

Learning a new library is always easier when you have working examples you can play with. jwh put many of them on his react-samples Github repo.

+ +
+

Some simple examples with Facebook's React framework

+ + +
+

React Chosen Wrapper #

+

Cheng Lou wrote a wrapper for the Chosen input library called react-chosen. It took just 25 lines to be able to use jQuery component as a React one.

+
React.renderComponent(
+  <Chosen noResultsText="No result" value="Harvest" onChange={doSomething}>
+    <option value="Facebook">Facebook</option>
+    <option value="Harvest">Harvest</option>
+  </Chosen>
+, document.body);
+

JSX and ES6 Template Strings #

+

Domenic Denicola wrote a slide deck about the great applications of ES6 features and one slide shows how we could use Template Strings to compile JSX at run-time without the need for a pre-processing phase.

+ +
+

React Presentation #

+

Tom Occhino and Jordan Walke, React developers, did a presentation of React at Facebook Seattle's office. Check out the first 25 minutes for the presentation and the remaining 45 for a Q&A. I highly recommend you watching this video.

+ +
+

Docs #

+

Pete Hunt rewrote the entirety of the docs for v0.4. The goal was to add more explanation about why we built React and what the best practices are.

+ +
+

Guides

+ + +
+ +
+
+

React v0.4.0

July 17, 2013 by Paul O'Shannessy

@@ -286,89 +384,6 @@ If you were using React without JSX previously, your code should still work.
-
-

Community Round-up #3

-

June 27, 2013 by Vjeux

-
-
-

The highlight of this week is that an interaction-heavy app has been ported to React. React components are solving issues they had with nested views.

-

Moving From Backbone To React #

-

Clay Allsopp successfully ported Propeller, a fairly big, interaction-heavy JavaScript app, to React.

- -
-

Subviews involve a lot of easy-to-forget boilerplate that Backbone (by design) doesn't automate. Libraries like Backbone.Marionette offer more abstractions to make view nesting easier, but they're all limited by the fact that Backbone delegates how and went view-document attachment occurs to the application code.

- -

React, on the other hand, manages the DOM and only exposes real nodes at select points in its API. The "elements" you code in React are actually objects which wrap DOM nodes, not the actual objects which get inserted into the DOM. Internally, React converts those abstractions into actual DOMElements and fills out the document accordingly. [...]

- -

We moved about 20 different Backbone view classes to React over the past few weeks, including the live-preview pane that you see in our little iOS demo. Most importantly, it's allowed us to put energy into making each component work great on its own, instead of spending extra cycles to ensure they function in unison. For that reason, we think React is a more scalable way to build view-intensive apps than Backbone alone, and it doesn't require you to drop-everything-and-refactor like a move to Ember or Angular would demand.

- -

Read the full post...

-
-

Grunt Task for JSX #

-

Eric Clemmons wrote a task for Grunt that applies the JSX transformation to your Javascript files. It also works with Browserify if you want all your files to be concatenated and minified together.

- -
-

Grunt task for compiling Facebook React's .jsx templates into .js

-
grunt.initConfig({
-  react: {
-    app: {
-      options: { extension: 'js' },
-      files: { 'path/to/output/dir': 'path/to/jsx/templates/dir' }
-
-

It also works great with grunt-browserify!

-
browserify: {
-  options: {
-    transform: [ require('grunt-react').browserify ]
-  },
-  app: {
-    src: 'path/to/source/main.js',
-    dest: 'path/to/target/output.js'
-
-

Check out the project ...

-
-

Backbone/Handlebars Nested Views #

-

Joel Burget wrote a blog post talking about the way we would write React-like components in Backbone and Handlebars.

- -
-

The problem here is that we're trying to maniplate a tree, but there's a textual layer we have to go through. Our views are represented as a tree - the subviews are children of CommentCollectionView - and they end up as part of a tree in the DOM. But there's a Handlebars layer in the middle (which deals in flat strings), so the hierarchy must be destructed and rebuilt when we render.

- -

What does it take to render a collection view? In the Backbone/Handlebars view of the world you have to render the template (with stubs), render each subview which replaces a stub, and keep a reference to each subview (or anything within the view that could change in the future).

- -

So while our view is conceptually hierarchical, due to the fact that it has to go through a flat textual representation, we need to do a lot of extra work to reassemble that structure after rendering.

- -

Read the full post...

-
-

JSRomandie Meetup #

-

Renault John Lecoultre from BugBuster did a React introduction talk at a JS meetup called JS Romandie last week.

- - -

CoffeeScript integration #

-

Vjeux used the fact that JSX is just a syntactic sugar on-top of regular JS to rewrite the React front-page examples in CoffeeScript.

- -
-

Multiple people asked what's the story about JSX and CoffeeScript. There is no JSX pre-processor for CoffeeScript and I'm not aware of anyone working on it. Fortunately, CoffeeScript is pretty expressive and we can play around the syntax to come up with something that is usable.

-
{div, h3, textarea} = React.DOM
-(div {className: 'MarkdownEditor'}, [
-  (h3 {}, 'Input'),
-  (textarea {onKeyUp: @handleKeyUp, ref: 'textarea'},
-    @state.value
-  )
-])
-
-

Read the full post...

-
-

Tutorial in Plain Javascript #

-

We've seen a lot of people comparing React with various frameworks. Ricardo Tomasi decided to re-implement the tutorial without any framework, just plain Javascript.

- -
-

Facebook & Instagram launched the React framework and an accompanying tutorial. Developer Vlad Yazhbin decided to rewrite that using AngularJS. The end result is pretty neat, but if you're like me you will not actually appreciate the HTML speaking for itself and doing all the hard work. So let's see what that looks like in plain javascript.

- -

Read the full post...

-
- -
-
- @@ -85,6 +85,89 @@
+
+

Community Round-up #3

+

June 27, 2013 by Vjeux

+
+
+

The highlight of this week is that an interaction-heavy app has been ported to React. React components are solving issues they had with nested views.

+

Moving From Backbone To React #

+

Clay Allsopp successfully ported Propeller, a fairly big, interaction-heavy JavaScript app, to React.

+ +
+

Subviews involve a lot of easy-to-forget boilerplate that Backbone (by design) doesn't automate. Libraries like Backbone.Marionette offer more abstractions to make view nesting easier, but they're all limited by the fact that Backbone delegates how and went view-document attachment occurs to the application code.

+ +

React, on the other hand, manages the DOM and only exposes real nodes at select points in its API. The "elements" you code in React are actually objects which wrap DOM nodes, not the actual objects which get inserted into the DOM. Internally, React converts those abstractions into actual DOMElements and fills out the document accordingly. [...]

+ +

We moved about 20 different Backbone view classes to React over the past few weeks, including the live-preview pane that you see in our little iOS demo. Most importantly, it's allowed us to put energy into making each component work great on its own, instead of spending extra cycles to ensure they function in unison. For that reason, we think React is a more scalable way to build view-intensive apps than Backbone alone, and it doesn't require you to drop-everything-and-refactor like a move to Ember or Angular would demand.

+ +

Read the full post...

+
+

Grunt Task for JSX #

+

Eric Clemmons wrote a task for Grunt that applies the JSX transformation to your Javascript files. It also works with Browserify if you want all your files to be concatenated and minified together.

+ +
+

Grunt task for compiling Facebook React's .jsx templates into .js

+
grunt.initConfig({
+  react: {
+    app: {
+      options: { extension: 'js' },
+      files: { 'path/to/output/dir': 'path/to/jsx/templates/dir' }
+
+

It also works great with grunt-browserify!

+
browserify: {
+  options: {
+    transform: [ require('grunt-react').browserify ]
+  },
+  app: {
+    src: 'path/to/source/main.js',
+    dest: 'path/to/target/output.js'
+
+

Check out the project ...

+
+

Backbone/Handlebars Nested Views #

+

Joel Burget wrote a blog post talking about the way we would write React-like components in Backbone and Handlebars.

+ +
+

The problem here is that we're trying to maniplate a tree, but there's a textual layer we have to go through. Our views are represented as a tree - the subviews are children of CommentCollectionView - and they end up as part of a tree in the DOM. But there's a Handlebars layer in the middle (which deals in flat strings), so the hierarchy must be destructed and rebuilt when we render.

+ +

What does it take to render a collection view? In the Backbone/Handlebars view of the world you have to render the template (with stubs), render each subview which replaces a stub, and keep a reference to each subview (or anything within the view that could change in the future).

+ +

So while our view is conceptually hierarchical, due to the fact that it has to go through a flat textual representation, we need to do a lot of extra work to reassemble that structure after rendering.

+ +

Read the full post...

+
+

JSRomandie Meetup #

+

Renault John Lecoultre from BugBuster did a React introduction talk at a JS meetup called JS Romandie last week.

+ + +

CoffeeScript integration #

+

Vjeux used the fact that JSX is just a syntactic sugar on-top of regular JS to rewrite the React front-page examples in CoffeeScript.

+ +
+

Multiple people asked what's the story about JSX and CoffeeScript. There is no JSX pre-processor for CoffeeScript and I'm not aware of anyone working on it. Fortunately, CoffeeScript is pretty expressive and we can play around the syntax to come up with something that is usable.

+
{div, h3, textarea} = React.DOM
+(div {className: 'MarkdownEditor'}, [
+  (h3 {}, 'Input'),
+  (textarea {onKeyUp: @handleKeyUp, ref: 'textarea'},
+    @state.value
+  )
+])
+
+

Read the full post...

+
+

Tutorial in Plain Javascript #

+

We've seen a lot of people comparing React with various frameworks. Ricardo Tomasi decided to re-implement the tutorial without any framework, just plain Javascript.

+ +
+

Facebook & Instagram launched the React framework and an accompanying tutorial. Developer Vlad Yazhbin decided to rewrite that using AngularJS. The end result is pretty neat, but if you're like me you will not actually appreciate the HTML speaking for itself and doing all the hard work. So let's see what that looks like in plain javascript.

+ +

Read the full post...

+
+ +
+
+

React v0.3.3

June 21, 2013 by Paul O'Shannessy

@@ -326,20 +409,6 @@ nuts and bolts
-
-

JSFiddle Integration

-

June 2, 2013 by Christopher Chedeau

-
-
-

JSFiddle just announced support for React. This is an exciting news as it makes collaboration on snippets of code a lot easier. You can play around this base React JSFiddle, fork it and share it! A fiddle without JSX is also available.

- - - - - -
-
-
diff --git a/blog/page6/index.html b/blog/page6/index.html new file mode 100644 index 0000000000..1741356443 --- /dev/null +++ b/blog/page6/index.html @@ -0,0 +1,141 @@ + + + + + + React | Blog + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+ + +
+ +
+

JSFiddle Integration

+

June 2, 2013 by Christopher Chedeau

+
+
+

JSFiddle just announced support for React. This is an exciting news as it makes collaboration on snippets of code a lot easier. You can play around this base React JSFiddle, fork it and share it! A fiddle without JSX is also available.

+ + + + + +
+
+ + + +
+
+ + + +
+
+ + + + diff --git a/feed.xml b/feed.xml index 5112c1ec52..2da65468c4 100644 --- a/feed.xml +++ b/feed.xml @@ -6,6 +6,87 @@ http://facebook.github.io/react + + Community Round-up #12 + <p>React got featured on the front-page of Hacker News thanks to the Om library. If you try it out for the first time, take a look at the <a href="/react/docs/getting-started.html">docs</a> and do not hesitate to ask questions on the <a href="http://groups.google.com/group/reactjs">Google Group</a>, <a href="irc://chat.freenode.net/reactjs">IRC</a> or <a href="http://stackoverflow.com/questions/tagged/reactjs">Stack Overflow</a>. We are trying our best to help you out!</p> +<h2><a class="anchor" name="the-future-of-javascript-mvc"></a>The Future of Javascript MVC <a class="hash-link" href="#the-future-of-javascript-mvc">#</a></h2> +<p><a href="http://swannodette.github.io/">David Nolan</a> announced Om, a thin wrapper on-top of React in ClojureScript. It stands out by only using immutable data structures. This unlocks the ability to write a very efficient <a href="http://facebook.github.io/react/docs/component-specs.html#updating-shouldcomponentupdate">shouldComponentUpdate</a> and get huge performance improvements on some tasks.</p> + +<blockquote> +<p>We&#39;ve known this for some time over here in the ClojureScript corner of the world - all of our collections are immutable and modeled directly on the original Clojure versions written in Java. Modern JavaScript engines have now been tuned to the point that it&#39;s no longer uncommon to see collection performance within 2.5X of the Java Virtual Machine.</p> + +<p>Wait, wait, wait. What does the performance of persistent data structures have to do with the future of JavaScript MVCs?</p> + +<p>A whole lot. +<figure><a href="http://swannodette.github.io/2013/12/17/the-future-of-javascript-mvcs/"><img src="/react/img/blog/om-backbone.png" alt=""></a></figure></p> + +<p><a href="http://swannodette.github.io/2013/12/17/the-future-of-javascript-mvcs/">Read the full article...</a></p> +</blockquote> +<h2><a class="anchor" name="scroll-position-with-react"></a>Scroll Position with React <a class="hash-link" href="#scroll-position-with-react">#</a></h2> +<p>Managing the scroll position when new content is inserted is usually very tricky to get right. <a href="http://blog.vjeux.com/">Vjeux</a> discovered that <a href="http://facebook.github.io/react/docs/component-specs.html#updating-componentwillupdate">componentWillUpdate</a> and <a href="http://facebook.github.io/react/docs/component-specs.html#updating-componentdidupdate">componentDidUpdate</a> were triggered exactly at the right time to manage the scroll position.</p> + +<blockquote> +<p>We can check the scroll position before the component has updated with componentWillUpdate and scroll if necessary at componentDidUpdate</p> +<div class="highlight"><pre><code class="text language-text" data-lang="text">componentWillUpdate: function() { + var node = this.getDOMNode(); + this.shouldScrollBottom = + (node.scrollTop + node.offsetHeight) === node.scrollHeight; +}, +componentDidUpdate: function() { + if (this.shouldScrollBottom) { + var node = this.getDOMNode(); + node.scrollTop = node.scrollHeight + } +}, +</code></pre></div> +<p><a href="http://blog.vjeux.com/2013/javascript/scroll-position-with-react.html">Check out the blog article...</a></p> +</blockquote> +<h2><a class="anchor" name="lights-out"></a>Lights Out <a class="hash-link" href="#lights-out">#</a></h2> +<p>React declarative approach is well suited to write games. <a href="https://github.com/chenglou">Cheng Lou</a> wrote the famous Lights Out game in React. It&#39;s a good example of use of <a href="http://facebook.github.io/react/docs/animation.html">TransitionGroup</a> to implement animations. +<figure><a href="http://chenglou.github.io/react-lights-out/"><img src="/react/img/blog/lights-out.png" alt=""></a></figure></p> + +<p><a href="http://chenglou.github.io/react-lights-out/">Try it out!</a></p> +<h2><a class="anchor" name="reactive-table-bookmarklet"></a>Reactive Table Bookmarklet <a class="hash-link" href="#reactive-table-bookmarklet">#</a></h2> +<p><a href="http://www.phpied.com/">Stoyan Stefanov</a> wrote a bookmarklet to process tables on the internet. It adds a little &quot;pop&quot; button that expands to a full-screen view with sorting, editing and export to csv and json. +<figure><a href="http://www.phpied.com/reactivetable-bookmarklet/"><img src="/react/img/blog/reactive-bookmarklet.png" alt=""></a></figure></p> + +<p><a href="http://www.phpied.com/reactivetable-bookmarklet/">Check out the blog post...</a></p> +<h2><a class="anchor" name="montagejs-tutorial-in-react"></a>MontageJS Tutorial in React <a class="hash-link" href="#montagejs-tutorial-in-react">#</a></h2> +<p><a href="https://twitter.com/ssorallen">Ross Allen</a> implemented <a href="http://montagejs.org/">MontageJS</a>&#39;s <a href="http://montagejs.org/docs/tutorial-reddit-client-with-montagejs.html">Reddit tutorial</a> in React. This is a good opportunity to compare the philosophies of the two libraries.</p> + +<iframe width="100%" height="300" src="http://jsfiddle.net/ssorallen/fEsYt/embedded/result,html,js" allowfullscreen="allowfullscreen" frameborder="0"></iframe> + +<p><a href="http://jsfiddle.net/ssorallen/fEsYt/">View the source on JSFiddle...</a></p> +<h2><a class="anchor" name="writing-good-react-components"></a>Writing Good React Components <a class="hash-link" href="#writing-good-react-components">#</a></h2> +<p><a href="http://blog.whn.se/">William Högman Rudenmalm</a> wrote an article on how to write good React components. This is full of good advice.</p> + +<blockquote> +<p>The idea of dividing software into smaller parts or components is hardly new - It is the essance of good software. The same principles that apply to software in general apply to building React components. That doesn’t mean that writing good React components is just about applying general rules.</p> + +<p>The web offers a unique set of challenges, which React offers interesting solutions to. First and foremost among these solutions is the what is called the Mock DOM. Rather than having user code interface with the DOM in a direct fashion, as is the case with most DOM manipulation libraries.</p> + +<p>You build a model of how you want the DOM end up like. React then inserts this model into the DOM. This is very useful for updates because React simply compares the model or mock DOM against the actual DOM, and then only updates based on the difference between the two states.</p> + +<p><a href="http://blog.whn.se/post/69621609605/writing-good-react-components">Read the full article ...</a></p> +</blockquote> +<h2><a class="anchor" name="hoodie-react-todomvc"></a>Hoodie React TodoMVC <a class="hash-link" href="#hoodie-react-todomvc">#</a></h2> +<p><a href="http://svenlito.com/">Sven Lito</a> integrated the React TodoMVC example within an <a href="http://hood.ie/">Hoodie</a> web app environment. This should let you get started using Hoodie and React.</p> +<div class="highlight"><pre><code class="text language-text" data-lang="text">hoodie new todomvc -t &quot;hoodiehq/hoodie-react-todomvc&quot; +</code></pre></div> +<p><a href="https://github.com/hoodiehq/hoodie-react-todomvc">Check out on GitHub...</a></p> +<h2><a class="anchor" name="jsx-compiler"></a>JSX Compiler <a class="hash-link" href="#jsx-compiler">#</a></h2> +<p>Ever wanted to have a quick way to see what a JSX tag would be converted to? <a href="http://www.yungsters.com/">Tim Yung</a> made a page for it. +<figure><a href="http://facebook.github.io/react/jsx-compiler.html"><img src="/react/img/blog/jsx-compiler.png" alt=""></a></figure></p> + +<p><a href="http://facebook.github.io/react/jsx-compiler.html">Try it out!</a></p> +<h2><a class="anchor" name="random-tweet"></a>Random Tweet <a class="hash-link" href="#random-tweet">#</a></h2> +<p><center><blockquote class="twitter-tweet" lang="en"><p>.<a href="https://twitter.com/jordwalke">@jordwalke</a> lays down some truth <a href="http://t.co/AXAn0UlUe3">http://t.co/AXAn0UlUe3</a>, optimizing your JS application shouldn&#39;t force you to rewrite so much code <a href="https://twitter.com/search?q=%23reactjs&amp;src=hash">#reactjs</a></p>&mdash; David Nolen (@swannodette) <a href="https://twitter.com/swannodette/statuses/413780079249215488">December 19, 2013</a></blockquote></center></p> + + 2013-12-23T00:00:00+01:00 + http://facebook.github.io/react/blog/2013/12/23/community-roundup-12.html + http://facebook.github.io/react/blog/2013/12/23/community-roundup-12.html + + React v0.8 <p>I&#39;ll start by answering the obvious question:</p> @@ -628,86 +709,5 @@ Is this some sort of template language? Specifically no. This might have been th http://facebook.github.io/react/blog/2013/09/24/community-roundup-8.html - - Community Round-up #7 - <p>It&#39;s been three months since we open sourced React and it is going well. Some stats so far:</p> - -<ul> -<li>114 285 unique visitors on this website</li> -<li><a href="https://github.com/facebook/react/stargazers">1933 stars</a> and <a href="https://github.com/facebook/react/network/members">210 forks</a></li> -<li><a href="https://groups.google.com/forum/#!forum/reactjs">226 posts on Google Group</a></li> -<li><a href="https://gist.github.com/vjeux/6335762">76 Github projects using React</a></li> -<li><a href="https://github.com/facebook/react/graphs/contributors">30 contributors</a></li> -<li><a href="http://facebook.github.io/react/blog/">15 blog posts</a></li> -<li>2 early adopters: <a href="http://benalpert.com/2013/06/09/using-react-to-speed-up-khan-academy.html">Khan Academy</a> and <a href="http://usepropeller.com/blog/posts/from-backbone-to-react/">Propeller</a></li> -</ul> -<h2><a class="anchor" name="wolfenstein-rendering-engine-ported-to-react"></a>Wolfenstein Rendering Engine Ported to React <a class="hash-link" href="#wolfenstein-rendering-engine-ported-to-react">#</a></h2> -<p><a href="http://www.petehunt.net/">Pete Hunt</a> ported the render code of the web version of Wolfenstein 3D to React. Check out <a href="http://www.petehunt.net/wolfenstein3D-react/wolf3d.html">the demo</a> and <a href="https://github.com/petehunt/wolfenstein3D-react/blob/master/js/renderer.js#L183">render.js</a> file for the implementation. -<figure><a href="http://www.petehunt.net/wolfenstein3D-react/wolf3d.html"><img src="/react/img/blog/wolfenstein_react.png" alt=""></a></figure></p> -<h2><a class="anchor" name="react-amp-meteor"></a>React &amp; Meteor <a class="hash-link" href="#react-amp-meteor">#</a></h2> -<p><a href="https://twitter.com/benjamn">Ben Newman</a> made a <a href="https://github.com/benjamn/meteor-react/blob/master/lib/mixin.js">13-lines wrapper</a> to use React and Meteor together. <a href="http://www.meteor.com/">Meteor</a> handles the real-time data synchronization between client and server. React provides the declarative way to write the interface and only updates the parts of the UI that changed.</p> - -<blockquote> -<p>This repository defines a Meteor package that automatically integrates the React rendering framework on both the client and the server, to complement or replace the default Handlebars templating system.</p> - -<p>The React core is officially agnostic about how you fetch and update your data, so it is far from obvious which approach is the best. This package provides one answer to that question (use Meteor!), and I hope you will find it a compelling combination.</p> -<div class="highlight"><pre><code class="javascript language-javascript" data-lang="javascript"><span class="kd">var</span> <span class="nx">MyComponent</span> <span class="o">=</span> <span class="nx">React</span><span class="p">.</span><span class="nx">createClass</span><span class="p">({</span> - <span class="nx">mixins</span><span class="o">:</span> <span class="p">[</span><span class="nx">MeteorMixin</span><span class="p">],</span> - - <span class="nx">getMeteorState</span><span class="o">:</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span> - <span class="k">return</span> <span class="p">{</span> <span class="nx">foo</span><span class="o">:</span> <span class="nx">Session</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="s1">&#39;foo&#39;</span><span class="p">)</span> <span class="p">};</span> - <span class="p">},</span> - - <span class="nx">render</span><span class="o">:</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span> - <span class="k">return</span> <span class="o">&lt;</span><span class="nx">div</span><span class="o">&gt;</span><span class="p">{</span><span class="k">this</span><span class="p">.</span><span class="nx">state</span><span class="p">.</span><span class="nx">foo</span><span class="p">}</span><span class="o">&lt;</span><span class="err">/div&gt;;</span> - <span class="p">}</span> -<span class="p">});</span> -</code></pre></div> -<p>Dependencies will be registered for any data accesses performed by getMeteorState so that the component can be automatically re-rendered whenever the data changes.</p> - -<p><a href="https://github.com/benjamn/meteor-react">Read more ...</a></p> -</blockquote> -<h2><a class="anchor" name="react-page"></a>React Page <a class="hash-link" href="#react-page">#</a></h2> -<p><a href="https://github.com/jordwalke">Jordan Walke</a> implemented a complete React project creator called <a href="https://github.com/facebook/react-page/">react-page</a>. It supports both server-side and client-side rendering, source transform and packaging JSX files using CommonJS modules, and instant reload.</p> - -<blockquote> -<p>Easy Application Development with React JavaScript -<figure><a href="https://github.com/facebook/react-page/"><img src="/react/img/blog/react-page.png" alt=""></a></figure></p> - -<p><strong>Why Server Rendering?</strong></p> - -<ul> -<li>Faster initial page speed: - -<ul> -<li>Markup displayed before downloading large JavaScript.</li> -<li>Markup can be generated more quickly on a fast server than low power client devices.</li> -</ul></li> -<li>Faster Development and Prototyping: - -<ul> -<li>Instantly refresh your app without waiting for any watch scripts or bundlers.</li> -</ul></li> -<li>Easy deployment of static content pages/blogs: just archive using recursive wget.</li> -<li>SEO benefits of indexability and perf.</li> -</ul> - -<p><strong>How Does Server Rendering Work?</strong></p> - -<ul> -<li><code>react-page</code> computes page markup on the server, sends it to the client so the user can see it quickly.</li> -<li>The corresponding JavaScript is then packaged and sent.</li> -<li>The browser runs that JavaScript, so that all of the event handlers, interactions and update code will run seamlessly on top of the server generated markup.</li> -<li>From the developer&#39;s (and the user&#39;s) perspective, it&#39;s just as if the rendering occurred on the client, only faster.</li> -</ul> - -<p><a href="https://github.com/facebook/react-page/">Try it out ...</a></p> -</blockquote> - - 2013-08-26T00:00:00+02:00 - http://facebook.github.io/react/blog/2013/08/26/community-roundup-7.html - http://facebook.github.io/react/blog/2013/08/26/community-roundup-7.html - - diff --git a/img/blog/jsx-compiler.png b/img/blog/jsx-compiler.png new file mode 100644 index 0000000000..ec6248c1a4 Binary files /dev/null and b/img/blog/jsx-compiler.png differ diff --git a/img/blog/lights-out.png b/img/blog/lights-out.png new file mode 100644 index 0000000000..702c80a3fb Binary files /dev/null and b/img/blog/lights-out.png differ diff --git a/img/blog/om-backbone.png b/img/blog/om-backbone.png new file mode 100644 index 0000000000..9a910486db Binary files /dev/null and b/img/blog/om-backbone.png differ diff --git a/img/blog/reactive-bookmarklet.png b/img/blog/reactive-bookmarklet.png new file mode 100644 index 0000000000..abe0dcabb3 Binary files /dev/null and b/img/blog/reactive-bookmarklet.png differ