ID photo of Ciro Santilli taken in 2013 right eyeCiro Santilli OurBigBook logoOurBigBook.com  Sponsor 中国独裁统治 China Dictatorship 新疆改造中心、六四事件、法轮功、郝海东、709大抓捕、2015巴拿马文件 邓家贵、低端人口、西藏骚乱
The goal of this example is to understand when states and effects happen when changing between different routes that use the same component.
Behavior is follows:
This is likely because in React the state kept in the virtual DOM structure, and identical structure implies identical state. So when we change from post 1 to 2, we still have a Post object, and state is unchanged.
Next if we click:
then the count is back to 0. This is because we changed the Post object in the DOM to Index and back, which resets everything.
This example also illustrates how to prevent this from happening with useEffect.
Bibliography:

Ancestors (13)

  1. Next.js example
  2. Next.js
  3. React
  4. List of front-end web frameworks
  5. Front-end web framework
  6. Web framework
  7. Web technology
  8. Software
  9. Computer
  10. Information technology
  11. Area of technology
  12. Technology
  13. Home