Next.js: [Question] is it normal that ComponentDidMount is triggerred twice when using next/link?

Created on 14 May 2017  路  3Comments  路  Source: vercel/next.js

So I have simply "single post page" that can be navigated through links (post?slug=x), and in getInitialProps Im dispatching action to get data for the singlePost, thing is that after clicking a link I have this scenario (in page single post page component):
shouldComponentUpdate -> componentDidUpdate -> componentDidUpdate (extra)
I would like to dispatch some additional actions after component will be loaded with the new post but its dispatching twice because of this.. or I just have a bug, but I spend some time on it already and it will be good to know if this is not a normal behaviour.

Menu with links: https://github.com/lzgrzebski/teachmesilence.com/blob/master/src/components/Menu/index.js
SinglePostContainer: https://github.com/lzgrzebski/teachmesilence.com/blob/master/src/containers/SinglePostContainer.js
post page: https://github.com/lzgrzebski/teachmesilence.com/blob/master/src/pages/post.js

bug

Most helpful comment

I'm using a layout for all my pages in my app, the layout is always the same but componentDidMount and componentWillUnmount are always called when switching pages. I expected them to run only once :c

All 3 comments

I'm using a layout for all my pages in my app, the layout is always the same but componentDidMount and componentWillUnmount are always called when switching pages. I expected them to run only once :c

@Goluis the whole page is re-rendered on page changes. Even if it's the same page with different params.

I think this was fixed when upgrading react-hot-loader. We're going to drop react-hot-loader all together soon.

Was this page helpful?
0 / 5 - 0 ratings