<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:series="http://organizeseries.com/"
	>

<channel>
	<title>小林徹 &#8211; HTML5Experts.jp</title>
	<atom:link href="/koba04/feed/" rel="self" type="application/rss+xml" />
	<link>https://html5experts.jp</link>
	<description>日本に、もっとエキスパートを。</description>
	<lastBuildDate>Sat, 07 Jul 2018 03:14:05 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.7.19</generator>
	<item>
		<title>Reactの最新動向とベストプラクティス ── HTML5 Conference 2016セッションレポート</title>
		<link>/koba04/20839/</link>
		<pubDate>Wed, 19 Oct 2016 00:00:17 +0000</pubDate>
		<dc:creator><![CDATA[小林徹]]></dc:creator>
				<category><![CDATA[最新動向]]></category>
		<category><![CDATA[プログラミング]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[React]]></category>
		<category><![CDATA[Redux]]></category>

		<guid isPermaLink="false">/?p=20839</guid>
		<description><![CDATA[連載： HTML5 Conference 2016 特集 (2)2016年9月3日に東京電機大学で開催された「HTML5 Conference 2016」のセッションを特集する第二弾は筆者である私、小林徹が登壇した「 R...]]></description>
				<content:encoded><![CDATA[<div class="seriesmeta">連載： <a href="https://html5experts.jp/series/html5-conf2016/" class="series-403" title="HTML5 Conference 2016 特集" data-wpel-link="internal">HTML5 Conference 2016 特集</a> (2)</div><p>2016年9月3日に東京電機大学で開催された「HTML5 Conference 2016」のセッションを特集する第二弾は筆者である私、小林徹が登壇した「 <a href="http://events.html5j.org/conference/2016/9/session/#session_id_h1" data-wpel-link="external" target="_blank" rel="follow external noopener noreferrer">Reactの最新動向とベストプラクティス</a>
」の内容を解説します。</p>

<p><img src="/wp-content/uploads/2016/10/DSC06341.jpg" alt="" width="640" height="400" class="alignnone size-full wp-image-21355" srcset="/wp-content/uploads/2016/10/DSC06341.jpg 640w, /wp-content/uploads/2016/10/DSC06341-300x188.jpg 300w, /wp-content/uploads/2016/10/DSC06341-207x129.jpg 207w" sizes="(max-width: 640px) 100vw, 640px" /></p>

<h2>Reactの現状</h2>

<p>Reactは、2013年にFacebookが公開した、Viewを作るためのJavaScriptのライブラリーです。</p>

<ul>
<li><a href="https://facebook.github.io/react/" data-wpel-link="external" target="_blank" rel="follow external noopener noreferrer">https://facebook.github.io/react/</a></li>
</ul>

<p>現在のバージョンは<code>v15.3.2</code>です。
<code>v1.0.0</code>から<code>v14.0.0</code>までのバージョンはありません。
「すでに安定していてプロダクションでも利用できる」ことや「セマンティック・バージョニング（<code>パッチ.マイナー.メジャー</code>）に準拠している」ことを示すために、<code>v0.14.8</code>からのバージョンアップ時に<code>v0.15.0</code>ではなく、マイナーのバージョン番号をメジャーにシフトさせて<code>v15.0.0</code>になりました。</p>

<p>Reactの採用事例を見ていきましょう。</p>

<p>Reactを開発しているFacebookは、ウェブページのコメント欄などで部分的にReactを使用しています。
同じくFacebookが運営しているInstagramでは、ウェブページ全体をReactのComponentで構築しています。</p>

<p>Facebook以外の事例を見てみると、NetflixやTwitter、Airbnb、Uberなど多くの企業でReactが使われています。
日本でも、Abema.tvなど大規模にReactが導入されている事例が増えています。</p>

<p>これらは、ReactのDeveloper Toolsを使用することで確認できます。</p>

<ul>
<li><a href="https://github.com/facebook/react-devtools" data-wpel-link="external" target="_blank" rel="follow external noopener noreferrer">https://github.com/facebook/react-devtools</a></li>
</ul>

<p><img src="/wp-content/uploads/2016/09/Screen-Shot-2016-09-20-at-22.34.23-640x438.png" alt="screen-shot-2016-09-20-at-22-34-23" width="640" height="438" class="aligncenter size-large wp-image-21095" srcset="/wp-content/uploads/2016/09/Screen-Shot-2016-09-20-at-22.34.23.png 640w, /wp-content/uploads/2016/09/Screen-Shot-2016-09-20-at-22.34.23-300x205.png 300w, /wp-content/uploads/2016/09/Screen-Shot-2016-09-20-at-22.34.23-207x142.png 207w" sizes="(max-width: 640px) 100vw, 640px" /></p>

<p>また、Electron製のターミナルソフトであるHypertermは、ReactとReduxを使って作られています。
機能拡張の仕組みを、Reduxのミドルウェアの仕組みで実現するなど興味深い点も多く、ソースコードはGitHubで公開されています。</p>

<ul>
<li><a href="https://github.com/zeit/hyperterm" data-wpel-link="external" target="_blank" rel="follow external noopener noreferrer">https://github.com/zeit/hyperterm</a></li>
</ul>

<p>他にもJenkinsが、新しいUI ComponentをReactのComponentとして提供しているなど、Reactはまさに「今使われているライブラリー」であることが言えます。</p>

<h2>特徴</h2>

<p>それではまず最初に、Reactの特徴について見ていきましょう。
Reactのサイトのトップには、「Declarative」、「Component-Based」、「Learn Once, Write Anywhere」の3つのキーワードが紹介されています。</p>

<p><img src="/wp-content/uploads/2016/09/Screen-Shot-2016-09-20-at-21.01.03-640x186.png" alt="Reactの特徴" width="640" height="186" class="aligncenter size-large wp-image-21092" srcset="/wp-content/uploads/2016/09/Screen-Shot-2016-09-20-at-21.01.03.png 640w, /wp-content/uploads/2016/09/Screen-Shot-2016-09-20-at-21.01.03-300x87.png 300w, /wp-content/uploads/2016/09/Screen-Shot-2016-09-20-at-21.01.03-207x60.png 207w" sizes="(max-width: 640px) 100vw, 640px" /></p>

<p>「Learn Once, Write Anywhere（一度学べば、どこでも書ける）」は、ReactにとってDOMは<code>react-dom</code>によるただの1つの環境であることを表しています。
<code>react-native</code>などを使うことで、「同じReactの考え方」でiOSやAndroidのような、DOM以外の環境をターゲットにしたアプリケーションを開発できます。</p>

<p>「Write Once, Run Anywhere（一度書けば、どこでも実行できる）」ではないのは、Viewは各プラットフォームのルールや特徴に応じて構築するべきであり、安易に共通化すべきでないことを意味しています。
しかしながらViewに関連しないロジックの多くは共通化できるとしており、実際にFacebookのAds Managerのアプリは、<code>react-native</code>を使うことでiOSとAndroidで80%以上のコードが共通化できているそうです。</p>

<p>それでは、DeclarativeとComponent-Basedについて見ていきます。</p>

<h3>Declarative</h3>

<p>Reactでは、Declarative（宣言的）にComponentを組み合わせてViewを構築します。
宣言的という言葉の通り、状態に対しての「あるべき姿」を宣言するように定義します。</p>

<p>例えば、イベントに対する処理を命令的に記述すると、下記のようになります。</p>

<p></p><pre class="crayon-plain-tag">// elに対する変化を書いている
button.on(‘click’, () =&gt; el.append(child));</pre><p></p>

<p>これを宣言的に書くと、下記のようになります。</p>

<p></p><pre class="crayon-plain-tag">// render関数は、渡されたstateに対するあるべき表示を定義している
render = state =&gt; {
  el.innerHTML = state.map(child =&gt; `&lt;div&gt;${child}&lt;/div&gt;`).join(‘’);
};

// 状態を更新して、render関数に渡す
button.on(‘click’, () =&gt; {
  state.push(child);
  render(state);
};</pre><p></p>

<p>上記の場合、render関数は受け取った<code>state</code>をもとにViewを構築するだけです。
これは、初期表示の場合もイベントによる更新時も常に同じです。</p>

<p>この結果、render関数は<code>state</code>のみに依存し、同じ<code>state</code>からは常に同じViewを構築します。
これは、テストやデバッグを容易にします。</p>

<p>ReactはComponentを使い、宣言的にViewを構築します。</p>

<p></p><pre class="crayon-plain-tag">const View = props =&gt; (
    &lt;div&gt;{props.items.map(item =&gt; &lt;div&gt;{item}&lt;/div&gt;)}&lt;/div&gt;
);</pre><p></p>

<h3>Component-Based</h3>

<p>Reactでは、Componentを作り、組み合わせることでViewを構築します。
Componentは、Appのようなアプリケーションを全体を表すものから、TextBoxのような既存の要素を少し拡張するようなものまで規模は様々です。</p>

<p></p><pre class="crayon-plain-tag">class App extends React.Component {
  constructor(...args) {
    super(...args);
    this.state = {
      text: '',
    };
  }
  render() {
    return (
      &lt;TextBox
        text={this.state.text}
        onChange={text =&gt; this.setState({text})}
      /&gt;
    );
  }
}
const TextBox = (text, onChange) =&gt; (
  &lt;div&gt;
    &lt;input type="text" onChange={e =&gt; onChange(e.target.value} /&gt;
    &lt;p&gt;{text}&lt;/p&gt;
  &lt;/div&gt;
);

ReactDOM.render(
  &lt;App /&gt;,
  document.getElementById('app')
);</pre><p></p>

<p>Componentは、<code>View = Component(State)</code>のような、Viewを作る関数として考えることができます。
Componentが返す<code>View</code>は、ReactElementのツリーとなります。
作成したReactElementのツリーは、ReactDOMによってDOMへと反映されます。
更新時は、更新前のReactElementのツリーと比較して、差分だけがDOMに反映されます。
これがVIRTUAL DOMと呼ばれる部分です。</p>

<p>この差分の反映により、Reactは関数のようにViewの構築を宣言的に書いた場合でも、パフォーマンスの劣化を避けることができます。
先ほど紹介したReactを使わない<code>innerHTML</code>による反映では、毎回DOMを再構築するため、規模が大きくなるとパフォーマンス上問題となります。</p>

<p><img src="/wp-content/uploads/2016/09/Screen-Shot-2016-09-20-at-20.16.55-640x476.png" alt="screen-shot-2016-09-20-at-20-16-55" width="640" height="476" class="aligncenter size-large wp-image-21084" srcset="/wp-content/uploads/2016/09/Screen-Shot-2016-09-20-at-20.16.55.png 640w, /wp-content/uploads/2016/09/Screen-Shot-2016-09-20-at-20.16.55-300x223.png 300w, /wp-content/uploads/2016/09/Screen-Shot-2016-09-20-at-20.16.55-207x154.png 207w" sizes="(max-width: 640px) 100vw, 640px" /></p>

<h2>Componentの作り方</h2>

<p>React Componentの作成方法には、下記の4種類あります。</p>

<ul>
<li>Stateless Functional Components</li>
<li>React.Component</li>
<li>React.PureComponent</li>
<li>React.createClass</li>
</ul>

<h3>Stateless Functinal Componenens</h3>

<p>関数によるComponentの定義方法です。</p>

<p></p><pre class="crayon-plain-tag">const Item = ({item}) =&gt; (
  &lt;div&gt;
    &lt;div&gt;{item.name}×{item.count}&lt;/div&gt;
  &lt;/div&gt;
);</pre><p></p>

<p>ただの関数であり、インスタンスも持たないのでStateやライフサイクルメソッドが定義できないなどの制限があります。
ですが最もシンプルな定義方法であり、Componentを作成する際は、まず最初にStateless Functional Componentsで定義できないかを考えることをオススメします。</p>

<p>SFCと省略して記述されることもあります。</p>

<h3>React.Component</h3>

<p>ComponentにStateを持たせたい場合や、ライフサイクルメソッドを使いたい場合にはReact.Componentを使った定義方法を使います。</p>

<p></p><pre class="crayon-plain-tag">class App extends React.Component {
  constructor(...args) { 
    super(...args);
    this.state = {
      user: null,
    };
  }
  componentDidMount() {
    fetch('/api/user')
    .then(res =&gt; res.json())
    .then(user =&gt; this.setState({user}))
    ;
  }
  render() {
    if (this.state.user == null) return &lt;Loading /&gt;;
    return (
      &lt;div&gt;
        &lt;User user={this.state.user} /&gt;
      &lt;/div&gt;
    );
  }
}</pre><p></p>

<h3>React.PureComponent</h3>

<p>パフォーマンスが問題となるような場面では、React.Componentの代わりにReact.PureComponentの利用を検討します。
React.PureComponentを使うことで、PropsとStateに対してのshallowEqual(浅い比較)がshouldComponentUpdateに適用されるようになります。</p>

<p>shouldComponentUpdateは、無駄なrenderメソッドの呼び出しを避けるためのライフサイクルメソッドです。</p>

<p></p><pre class="crayon-plain-tag">class Counter extends React.PureComponent {
  constructor(...args) {
    super(...args);
    this.state = {count: 0};
  }
  render() {
    return (
      &lt;div&gt;
        &lt;p&gt;{this.props.label}:{this.state.count}&lt;/p&gt;
        &lt;button
          onClick={() =&gt; this.setState({count: this.state.count + 1})
        /&gt;
     &lt;/div&gt;
    );
  }
}</pre><p></p>

<p>React.PureComponentは、PropsやStateのデータをイミュータブルに扱っている場合に利用できます。
イミュータブルであることが保証出来ない場合は、React.Componentを使い、<code>shouldComponentUpdate</code>を自ら実装する必要があります。</p>

<p>ただし、最適化は<code>react-addons-perf</code>を使い、問題となっている部分を計測して確認してから行うことをオススメします。</p>

<h3>React.creteClass</h3>

<p>React.createClassは、最初から存在するComponentの作成方法です。
ですが、今後は緩やかに非推奨の方向に進んでいます。</p>

<h3>Componentの拡張</h3>

<p>Reactでは、Componentの拡張を継承ではなく、Higher Order Components(HOC)を使ったCompositionで行うパターンが推奨されています。</p>

<p>Higher Order Componentsとは、高階関数（Higher Order Function）のComponent版と考えることができます。
Higher Order Functionは関数を引数や戻り値とする関数です。</p>

<p><a href="https://ja.wikipedia.org/wiki/%E9%AB%98%E9%9A%8E%E9%96%A2%E6%95%B0" data-wpel-link="external" target="_blank" rel="follow external noopener noreferrer">https://ja.wikipedia.org/wiki/高階関数</a></p>

<ul>
<li>Higher Order Functionの例</li>
</ul>

<p></p><pre class="crayon-plain-tag">// 何かする関数を受け取って、結果をログ出して返す
const logger = operation =&gt; (...args) =&gt; {
    const result = operation(...args);
    console.log(result);
    return result;
};
const add = logger((a, b) =&gt; a + b);
add(10, 20);
// 30</pre><p></p>

<p>Higher Order Componentsでは、Componentを引数として受け取り、それをラップした新しいComponentを返します。</p>

<ul>
<li>Higher Order Componentsの例</li>
</ul>

<p></p><pre class="crayon-plain-tag">// Componentを受け取って、PureComponentでラップして返す
const pure = Component =&gt; (
  class Pure extends React.PureComponent {
    render() {
      return &lt;Component ...{this.props}/&gt;;
    }
  }
);
const Item = ({name}) =&gt; &lt;div&gt;{name}&lt;/div&gt;;
const PureItem = pure(Item);
// &lt;PureItem name=“foo” /&gt;</pre><p></p>

<p>Higher Order Componentsのパターンは、<code>react-router</code>や<code>react-redux</code>などのライブラリーでも使われています。</p>

<p>また、Higher Order Componentsのパターンを集めた<code>recompose</code>というライブラリーもあります。</p>

<ul>
<li><a href="https://github.com/acdlite/recompose" data-wpel-link="external" target="_blank" rel="follow external noopener noreferrer">https://github.com/acdlite/recompose</a></li>
</ul>

<p></p><pre class="crayon-plain-tag">// isLoadedによってComponentを出し分ける
const enhance = branch(
  props =&gt; props.isLoaded,
  Component =&gt; Component,
  () =&gt; Loading
);
const LoadUser = enhance(User);
// &lt;LoadUser isLoaded={isLoaded} user={user} /&gt;</pre><p></p>

<h2>State管理</h2>

<p>Reactでは、Componentは<code>View = Component(State)</code>であると紹介しました。
したがって、Componentにはなるべく状態を持たせないことが推奨されます。</p>

<p>これにより、親Componentだけに状態管理が集約します。
親Componentは、子Componentに「状態」と「状態を変更するための関数」を渡します。
子以下のComponentは、それらを受け取り利用するだけです。</p>

<p><img src="/wp-content/uploads/2016/09/Screen-Shot-2016-09-20-at-21.40.54-640x462.png" alt="screen-shot-2016-09-20-at-21-40-54" width="640" height="462" class="aligncenter size-large wp-image-21093" srcset="/wp-content/uploads/2016/09/Screen-Shot-2016-09-20-at-21.40.54.png 640w, /wp-content/uploads/2016/09/Screen-Shot-2016-09-20-at-21.40.54-300x217.png 300w, /wp-content/uploads/2016/09/Screen-Shot-2016-09-20-at-21.40.54-207x149.png 207w" sizes="(max-width: 640px) 100vw, 640px" /></p>

<p><code>ViewTree = ComponentTree(State)</code></p>

<p>親Componentに状態管理が集約されることで、アプリケーションの状態を把握することが容易になります。
それと同時に、子Componentはほとんどロジックを持たず、状態を受け取りViewを構築するStateless Functional Componentsで定義可能なただの関数になります。
これによりテストも容易になります。
加えて、親のComponentは状態管理、子のComponentは見た目に関してと、役割を明確に分けることができます。</p>

<p>しかしながら、このパターンの場合、親Componentに処理が集中するため、規模が大きくなると管理が難しくなります。
その解決方法として、Facebookが発表したFluxというアーキテクチャがあります。</p>

<p><img src="/wp-content/uploads/2016/09/flux-diagram-white-background-640x319.png" alt="flux-diagram-white-background" width="640" height="319" class="aligncenter size-large wp-image-21086" srcset="/wp-content/uploads/2016/09/flux-diagram-white-background.png 640w, /wp-content/uploads/2016/09/flux-diagram-white-background-300x150.png 300w, /wp-content/uploads/2016/09/flux-diagram-white-background-207x103.png 207w" sizes="(max-width: 640px) 100vw, 640px" /></p>

<p>Fluxでは、状態管理の流れを役割ごとに細かく分割し、React Componentから切り離します。</p>

<p>Fluxの影響を受けているライブラリーとして、Reduxがあります。
Reduxは、状態管理のためのライブラリーです。</p>

<ul>
<li><a href="http://redux.js.org/" data-wpel-link="external" target="_blank" rel="follow external noopener noreferrer">http://redux.js.org/</a></li>
</ul>

<p>Reduxでは、アプリケーションの状態をシリアライズ可能な1つのオブジェクトにまとめます。
状態の更新は、Actionを発行して、Reducerと呼ばれるActionを元に新しい状態を作成する関数によって行われます。</p>

<p><img src="/wp-content/uploads/2016/09/Screen-Shot-2016-09-20-at-20.26.20-640x467.png" alt="screen-shot-2016-09-20-at-20-26-20" width="640" height="467" class="aligncenter size-large wp-image-21087" srcset="/wp-content/uploads/2016/09/Screen-Shot-2016-09-20-at-20.26.20.png 640w, /wp-content/uploads/2016/09/Screen-Shot-2016-09-20-at-20.26.20-300x219.png 300w, /wp-content/uploads/2016/09/Screen-Shot-2016-09-20-at-20.26.20-207x151.png 207w" sizes="(max-width: 640px) 100vw, 640px" /></p>

<p>Reduxでは、React ComponentをContainer ComponentとPresentational Componentの2つの役割に分けます。
それぞれの役割は以下の通りです。</p>

<p><img src="/wp-content/uploads/2016/09/Screen-Shot-2016-09-20-at-20.27.15-640x465.png" alt="screen-shot-2016-09-20-at-20-27-15" width="640" height="465" class="aligncenter size-large wp-image-21088" srcset="/wp-content/uploads/2016/09/Screen-Shot-2016-09-20-at-20.27.15.png 640w, /wp-content/uploads/2016/09/Screen-Shot-2016-09-20-at-20.27.15-300x218.png 300w, /wp-content/uploads/2016/09/Screen-Shot-2016-09-20-at-20.27.15-207x150.png 207w" sizes="(max-width: 640px) 100vw, 640px" /></p>

<p>Reduxでは、データはシリアライズ可能なオブジェクトとして単一のStoreに保持されるため、各処理は入力を受け取り入力に応じた結果を出力するただの関数として実装できます。</p>

<ul>
<li>アクションの発行 &#8211; <code>action = ActionCreator([event])</code></li>
<li>状態の更新 &#8211; <code>newState = Reducer(state, action)</code></li>
<li>状態の取得 &#8211; <code>props = Selector(state)</code></li>
</ul>

<p>これにより、各部分もPresentational Componentのように簡単にテストができます。</p>

<p>状態と処理を切り離し、ActionとStateをシリアライズ可能なオブジェクトにすることは、デバッグや状態の再現を容易にします。
それを利用したRedux DevTools Extensionでは、Actionを記録して任意のActionの流れを再現するだけでなく、指定したActionの流れをJSONとしてインポート・エクスポートできます。
これにより、処理の流れを複数人で共有したり、エラーがあった場合にサーバーに送信することで、状況の再現が可能になります。</p>

<p><img src="/wp-content/uploads/2016/09/Screen-Shot-2016-09-21-at-1.26.03-PM-640x480.png" alt="screen-shot-2016-09-21-at-1-26-03-pm" width="640" height="480" class="aligncenter size-large wp-image-21097" srcset="/wp-content/uploads/2016/09/Screen-Shot-2016-09-21-at-1.26.03-PM.png 640w, /wp-content/uploads/2016/09/Screen-Shot-2016-09-21-at-1.26.03-PM-300x225.png 300w, /wp-content/uploads/2016/09/Screen-Shot-2016-09-21-at-1.26.03-PM-207x155.png 207w" sizes="(max-width: 640px) 100vw, 640px" /></p>

<ul>
<li><a href="https://github.com/zalmoxisus/redux-devtools-extension" data-wpel-link="external" target="_blank" rel="follow external noopener noreferrer">https://github.com/zalmoxisus/redux-devtools-extension</a></li>
</ul>

<p>Reduxを使う場合、副作用や非同期処理の扱いを、Middlewareのレイヤーで吸収します。
Middlewareは発行されたActionを改変したり別のActionを発行するなど、アプリケーションの処理に大きく影響を与える部分です。
副作用や非同期処理を扱うためのMiddlewareは、すでにたくさん公開されています。
したがって、アプリケーションの要件に適した、副作用や非同期処理の方法を選択できます。</p>

<p>FluxアーキテクチャやReduxは、必要と感じるまで利用する必要はありません。
ですが、Reduxを使わない場合でも、React ComponentをContainer ComponentとPresentational Componentに分けて考えることは重要です。</p>

<h2>エコシステム</h2>

<p>Reactでは、すでに多くのエコシステムが存在します。
React Componentのテストを簡単に書くための仕組みを提供してくれるEnzymeや、Component単位でデザインを確認しながら開発できるReact StorybookなどOSSからたくさんのライブラリーやツールが公開されています。</p>

<ul>
<li><a href="http://airbnb.io/enzyme/" data-wpel-link="external" target="_blank" rel="follow external noopener noreferrer">http://airbnb.io/enzyme/</a></li>
<li><a href="https://getstorybook.io/" data-wpel-link="external" target="_blank" rel="follow external noopener noreferrer">https://getstorybook.io/</a></li>
</ul>

<p>また、React ComponentやJSXのためのESLintのプラグインも存在します。</p>

<ul>
<li><a href="https://github.com/yannickcr/eslint-plugin-react" data-wpel-link="external" target="_blank" rel="follow external noopener noreferrer">https://github.com/yannickcr/eslint-plugin-react</a></li>
</ul>

<p>コーディングのスタイルだけでなく、廃止予定のAPIの使用や、ベストプラクティスに沿っているかなど数多くの観点からのチェックが可能です。
ESLintとともに利用をオススメします。</p>

<p><img src="/wp-content/uploads/2016/09/Screen-Shot-2016-09-20-at-20.29.16-640x455.png" alt="screen-shot-2016-09-20-at-20-29-16" width="640" height="455" class="aligncenter size-large wp-image-21089" srcset="/wp-content/uploads/2016/09/Screen-Shot-2016-09-20-at-20.29.16.png 640w, /wp-content/uploads/2016/09/Screen-Shot-2016-09-20-at-20.29.16-300x213.png 300w, /wp-content/uploads/2016/09/Screen-Shot-2016-09-20-at-20.29.16-207x147.png 207w" sizes="(max-width: 640px) 100vw, 640px" /></p>

<p>また、a11yに対するチェックを行う<code>eslint-plugin-jsx-a11y</code>というプラグインもあります。</p>

<ul>
<li><a href="https://github.com/evcohen/eslint-plugin-jsx-a11y" data-wpel-link="external" target="_blank" rel="follow external noopener noreferrer">https://github.com/evcohen/eslint-plugin-jsx-a11y</a></li>
</ul>

<h2>将来</h2>

<p>Reactは、Facebookが開発しているライブラリーです。
Facebookの内部ではすでに25,000以上のReact Componentがあるそうで、ReactはFacebookの中でも重要な位置付けのライブラリーとなっています。
そのためFacebookが必要としている機能に対する優先度は当然高くなりますが、今後も継続してメンテナンスされることが期待できます。</p>

<p>加えて、OSSとしての役割も重要視されています。
例えば、SVGやcustom elementsの対応のようなFacebookでは必要とされていない機能も必要であればReact本体でサポートされます。
また、ReactのコアチームのミーティングノートをGitHubで公開したり、コマンド1つでReactを使ったアプリケーションの雛型を作成する<code>create-react-app</code>もその1つです。</p>

<ul>
<li><a href="https://github.com/reactjs/core-notes" data-wpel-link="external" target="_blank" rel="follow external noopener noreferrer">https://github.com/reactjs/core-notes</a></li>
<li><a href="https://github.com/facebookincubator/create-react-app" data-wpel-link="external" target="_blank" rel="follow external noopener noreferrer">https://github.com/facebookincubator/create-react-app</a></li>
</ul>

<p>前述した通り、Facebookだけでなく多くの企業がReactをプロダクションで使用しています。
そのため、Reactは非互換な変更に対してはとても慎重です。</p>

<p>何かAPIを廃止する場合は、「次のメジャーバージョンで警告の出力と移行プランの提供」、「その次のメジャーバージョンで廃止」という流れになります。
したがって、メジャーバージョンアップで突然動作しなくなることがないように配慮されています。</p>

<p>現在進行中の大きな開発として、「ReactFiber」があります。
ReactFiberは、ComponentとRendererがやりとりする、Reactのコアとなるアルゴリズムを全面的に書き直すものです。</p>

<p>現在は、更新処理からReactElementの差分計算・DOMへの反映までが同期的に行われています。
これは、規模の大きなComponentツリーや60FPSが求められるような場面で問題となることがあります。</p>

<p>ReactFiberでは、更新処理をFiberというタスクの単位で非同期に処理できるようになります。
例えば、アニメーションの更新処理など遅延が許されないものは、<code>requestAnimationFrame</code>を使い可能な限りすぐに反映し、APIのレスポンスや画面に表示されてない部分は、<code>requestIdleCallback</code>を使い多少の遅延を許容するといった具合です。</p>

<p><img src="/wp-content/uploads/2016/09/Screen-Shot-2016-09-20-at-20.30.29-640x468.png" alt="screen-shot-2016-09-20-at-20-30-29" width="640" height="468" class="aligncenter size-large wp-image-21090" srcset="/wp-content/uploads/2016/09/Screen-Shot-2016-09-20-at-20.30.29.png 640w, /wp-content/uploads/2016/09/Screen-Shot-2016-09-20-at-20.30.29-300x219.png 300w, /wp-content/uploads/2016/09/Screen-Shot-2016-09-20-at-20.30.29-207x151.png 207w" sizes="(max-width: 640px) 100vw, 640px" /></p>

<p>ReactFiberは、現在ベースとなる部分が実装中であり、すぐに現在のアルゴリズムと置き換えられるものではありません。
しかしながら、今後注目すべき動向の1つです。</p>

<h2>まとめ</h2>

<p>ReactはComponentを使いViewを構築するためのライブラリーです。
そのためReactが担う範囲は広くありません。しかし、Reactを使うことでクライアントでの状態管理の難しさを排除し、シンプルに考えることができます。</p>

<p>また、Facebookのサイト自体もそうであるように、ReactはSingle Page Applicationではないアプリケーションに対しても、部分的に導入していくことが可能です。
その際に必要となる、設計としては綺麗とは言えないようなAPIも提供しています。</p>

<p>Reactを取り巻くエコシステムは大きくなっており、それらの組み合わせを紹介する記事も多く存在します。</p>

<p>しかしながら、Reactをこれから初めてみようと思っている場合は、最低限の構成で小さく始めることをオススメします。その後、必要だと思った段階で、エコシステムが提供するライブラリーの導入を順番に検討してください。</p>

<p>そうすることで、各ライブラリーが、「何を」問題と考えて「どのように」解決しようとしているのかを理解できるようになります。その結果、多くの情報やライブラリーに振り回されることなく、エコシステムと付き合っていけるようになると考えています。</p>

<h3>上記の基調講演は動画でも公開中です</h3>

<p>当日の資料と動画は下記で公開されていますので、こちらも参照してください。</p>


<!-- iframe plugin v.4.3 wordpress.org/plugins/iframe/ -->
<iframe class="embedly-embed" src="//cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fspeakerdeck.com%2Fplayer%2F9919e9af69054589a3b1ad370a77a634&amp;url=https%3A%2F%2Fspeakerdeck.com%2Fkoba04%2Freactfalsezui-xin-dong-xiang-tobesutopurakuteisu&amp;image=https%3A%2F%2Fspeakerd.s3.amazonaws.com%2Fpresentations%2F9919e9af69054589a3b1ad370a77a634%2Fslide_0.jpg&amp;key=internal&amp;type=text%2Fhtml&amp;schema=speakerdeck" scrolling="no" frameborder="0" 0="allowfullscreen" width="100%" height="500"></iframe>



<!-- iframe plugin v.4.3 wordpress.org/plugins/iframe/ -->
<iframe src="https://www.youtube.com/embed/sNjCELYzEkU" frameborder="0" 0="allowfullscreen" width="100%" height="500" scrolling="yes" class="iframe-class"></iframe>

]]></content:encoded>
		
		<series:name><![CDATA[HTML5 Conference 2016 特集]]></series:name>
	</item>
	</channel>
</rss>
