mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
React 16 blog post and docs
This commit is contained in:
@@ -36,6 +36,7 @@
|
||||
<script src="https://unpkg.com/codemirror@5.15.2/mode/javascript/javascript.js"></script>
|
||||
<script src="https://unpkg.com/codemirror@5.15.2/mode/xml/xml.js"></script>
|
||||
<script src="https://unpkg.com/codemirror@5.15.2/mode/jsx/jsx.js"></script>
|
||||
<script src="https://unpkg.com/prop-types/prop-types.min.js"></script>
|
||||
<script src="https://unpkg.com/react/dist/react.min.js"></script>
|
||||
<script src="https://unpkg.com/react-dom/dist/react-dom.min.js"></script>
|
||||
<script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>
|
||||
@@ -63,7 +64,7 @@
|
||||
</ul>
|
||||
<ul class="nav-site nav-site-external">
|
||||
<li><a href="https://github.com/facebook/react">GitHub</a></li>
|
||||
<li><a href="https://github.com/facebook/react/releases">v15.6.2</a></li>
|
||||
<li><a href="https://github.com/facebook/react/releases">v16.0.0</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1127,7 +1128,7 @@
|
||||
<span class="c1">// this method has not changed</span>
|
||||
<span class="p">}</span>
|
||||
</code></pre></div>
|
||||
<p>Then update <code>stepNumber</code> when a new move is made by adding <code>stepNumber: history.length</code> to the state update in Game's <code>handleClick</code>:</p>
|
||||
<p>Then update <code>stepNumber</code> when a new move is made by adding <code>stepNumber: history.length</code> to the state update in Game's <code>handleClick</code>. We'll also update <code>handleClick</code> to be aware of <code>stepNumber</code> when reading the current board state so that you can go back in time then click in the board to create a new entry.:</p>
|
||||
<div class="highlight"><pre><code class="language-javascript" data-lang="javascript"> <span class="nx">handleClick</span><span class="p">(</span><span class="nx">i</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="hll"> <span class="kr">const</span> <span class="nx">history</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">state</span><span class="p">.</span><span class="nx">history</span><span class="p">.</span><span class="nx">slice</span><span class="p">(</span><span class="mi">0</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">stepNumber</span> <span class="o">+</span> <span class="mi">1</span><span class="p">);</span>
|
||||
</span> <span class="kr">const</span> <span class="nx">current</span> <span class="o">=</span> <span class="nx">history</span><span class="p">[</span><span class="nx">history</span><span class="p">.</span><span class="nx">length</span> <span class="o">-</span> <span class="mi">1</span><span class="p">];</span>
|
||||
@@ -1157,8 +1158,6 @@
|
||||
|
||||
<p>If you click any move link now, the board should immediately update to show what the game looked like at that time.</p>
|
||||
|
||||
<p>You may also want to update <code>handleClick</code> to be aware of <code>stepNumber</code> when reading the current board state so that you can go back in time then click in the board to create a new entry. (Hint: It's easiest to <code>.slice()</code> off the extra elements from <code>history</code> at the very top of <code>handleClick</code>.)</p>
|
||||
|
||||
<h3>Wrapping Up</h3>
|
||||
|
||||
<p>Now, you've made a tic-tac-toe game that:</p>
|
||||
|
||||
Reference in New Issue
Block a user