kuy / redux-tower

Saga powered routing engine for Redux app.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Why don't you use React element instead of React class?

rchaser53 opened this issue · comments

I want to use React element instead of React class.
Like below.

// now
const routes = {
    '/': Index               
};
// proposal
const routes = {           
    '/': <Index propA={'test'} />
};

I think this style is useful for reusing the same class (ex. Error page).
It a painful to use higher order component for using same React Class.

@rchaser53 Aha, I didn't think it...! It looks there are lots of benefits.

There is one thing I'm wondering. The right hand of a route definition (React element or React class) is stored in the Redux's state. So If I use React element, the state will keep a reference of instantiated components. In other words, the current implementation instantiates a component from React class every time.

The current implementation instantiates react class components every time, because of using createElement. And I also thought, my proposal instantiated every time. So I confirmed my proposal implementation and I found it doesn't instantiate after the second time. It only call render, not constructor. No problem. (First time is when transition from other component.)

If you don't mind, I'll rewrite my code and send the PR.

Thanks for the proof of concept 😃 I'm thinking about what are expected behaviors for us. In the case of React element is associated with a route action, it keeps the React's state when the component is shown again by the router (this means second time or later).

Anyway, I'm welcome your PR and happy to review!

In my opinion, I don't recommend the constructor is called every time.
Some page use the url for initial rendering and don't transition the page but change the url.
So I guess the idea is not good.