I know have a Header component present in all my pages in a IonPage component but I would like it to not “refresh/reload” on each page changing, is it possible to add it in App.tsx to do this ?
Just my thoughts… before you go down a rabbit hole regarding performance and re-renders, make sure it is time well spent
Pitfall #4: Overthinking performance : He adds, “unnecessary re-renders” are not necessarily bad for performance. Just because a component re-renders, doesn’t mean the DOM will get updated (updating the DOM can be slow). React does a great job at optimizing itself; it’s fast by default.
Need more code to better understand problem… you can create a sample project in codesandbox.io
Thanks a lot for your answer !
I understand that re-renders are not so bad, I am confident in React for optimization
What I meant, want, is not to optimize but only to have a better fluidity on my website.
I re-explain. I have a Header with the logo, some links… which is present on all pages. When I navigate and change page I see the header re-rendering.
What I would like it is to keep it, making the rest of the page to load/reload but not the Header.
I’m not sure a lot more code would be useful but some images could be
As you can see I have <Header /> on both pages, what I would like is to put this component in App.tsx to not see it re-render when changing page, an optionally to not write it in every pages
It’s not really visible but as you can see on the GIF, when I change page you have the animation on the whole page, on the Header too. I would like to keep Header in place
While I highly recommend you follow the standard of having the header on each page, I have the setup you are talking about and it seems to work well. Given that it’s not recommended it could break with any Ionic update, but if you must do it here is how I structured my app:
It seems that I found what was causing the effect which disturbs me: the routerDirection.
To explain, in my Menu I put routerDirection='none' and there isn’t this animation of “reloading”, but where I didn’t specify routerDirection the default value is forward.
According to thisrouterDirection is just for animation.
In conclusion, putting routerDirection='none' resolves the problem !
I actually have an history.push somewhere, I have now to find how to do this here