<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Michael Dawson</title>
    <description>The latest articles on DEV Community by Michael Dawson (@nippysaurus).</description>
    <link>https://dev.to/nippysaurus</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F269401%2F68964e0e-2c12-4709-9a4c-e4fa0a2935f5.png</url>
      <title>DEV Community: Michael Dawson</title>
      <link>https://dev.to/nippysaurus</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nippysaurus"/>
    <language>en</language>
    <item>
      <title>Unexpected getSnapshotBeforeUpdate behaviour</title>
      <dc:creator>Michael Dawson</dc:creator>
      <pubDate>Mon, 11 Nov 2019 11:55:36 +0000</pubDate>
      <link>https://dev.to/nippysaurus/unexpected-getsnapshotbeforeupdate-behaviour-50c0</link>
      <guid>https://dev.to/nippysaurus/unexpected-getsnapshotbeforeupdate-behaviour-50c0</guid>
      <description>&lt;p&gt;So I'm reading the documentation for &lt;a href="https://reactjs.org/docs/react-component.html#getsnapshotbeforeupdate" rel="noopener noreferrer"&gt;getSnapshotBeforeUpdate&lt;/a&gt; and it quite clearly outlines the exact use case I need it for (moving the scroll position when the page content moves). It also shows an example of reading the previous props (&lt;code&gt;prevProps&lt;/code&gt;) and comparing them to the current props (&lt;code&gt;this.props&lt;/code&gt;) to see if the number of items in the list has changed. I'm doing the same thing in my application, but I'm getting some odd behavior. Instead of the &lt;code&gt;prevProps&lt;/code&gt; having the previous value and &lt;code&gt;this.props&lt;/code&gt; having the current values, it behaves like this once then these values both change at once.&lt;/p&gt;

&lt;p&gt;For example if I was assigning a prop each letter of the alphabet this is what the outcome would be:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;getSnapshotBeforeUpdate call num&lt;/th&gt;
&lt;th&gt;&lt;code&gt;prevProps&lt;/code&gt;&lt;/th&gt;
&lt;th&gt;&lt;code&gt;this.props&lt;/code&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;a&lt;/td&gt;
&lt;td&gt;b&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;c&lt;/td&gt;
&lt;td&gt;c&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;d&lt;/td&gt;
&lt;td&gt;d&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Does this seem like expected behaviour?&lt;/p&gt;

&lt;p&gt;The only thing I can think of is that I have this component wrapped in a redux store, so maybe that is doing something funky with the parameters? I'm really at a bit of a loss as to what is going on.&lt;/p&gt;

</description>
      <category>react</category>
    </item>
  </channel>
</rss>
