diegohaz / arc

React starter kit based on Atomic Design
https://arc.js.org
2.92k stars 294 forks source link

The template components are re-created on every route change #252

Closed branchard closed 7 years ago

branchard commented 7 years ago

In src-example the template components are re-created on every route change because react will create a separate instance of your Layout for each route. It's annoying because react will re-generate template's DOM on every route change and every child components of this template will be reset.

Please fix your router structure.

branchard commented 7 years ago

Why did you close my issue? This is a real problem with your structure.

For example if I put an input in your Header component (in "src-example"), the input will be reset on every route change: peek 15-05-2017 19-16

diegohaz commented 7 years ago

I'm sorry, @branchard. I wrote an answer but forgot to send it. 😅

That's how react-router works. It re-mounts components on every route change. Since templates are inside pages, they are re-mounted as well.

You need to put those components (e.g. Header) outside of the page (e.g. in the App component).

Edit Also, if your problem is related to the form state, I recommend you to use redux-form or another way to keep the form state on the redux store.

branchard commented 7 years ago

With Atomic Design methodology Header must be in a page or a template. There is no other way than to put Header outside of the page ?

I think it's not optimized/clean to re-mouts whole template on each route change :confused:

diegohaz commented 7 years ago

You can create an AppTemplate and use it on App. There's nothing wrong with that.