Don't wrap with React.createElement unless needed
https://github.com/rackt/react-router/blob/master/modules/createRouter.js#L513
Currently causes react to emit a warning if you give a factory or existing ReactElement class as a handler in react-router. Very confusing for people who don't use JSX and are told by the React docs to ALWAYS wrap your components with createFactory if you want to use them without JSX, only to find out that react-router is doing wrapping you can't opt out of.
Warning: This JSX uses a plain function. Only React components are valid in React's JSX transform.
Only problem is I don't think we can detect if you give us a ReactElement or a factory. That's why we don't tell you anywhere in our docs to give us a factory.
Maybe we could fix it with a FAQ?
@mjackson What about an option for disabling the wrapping? If not I will probably have to fork and maintain a separate repo that doesn't wrap for you. I'm dealing with a situation where I have to support the result of createFactory
Also causing warnings to be logged when using RouteHandler https://github.com/rackt/react-router/blob/master/modules/RouteHandlerMixin.js#L43
What about an option for disabling the wrapping?
The only way we could unwrap your factory to get at the underlying component class would be to access the deprecated type property on the factory. The type property is also exposed on component classes, but it's deprecated there as well.
Why can't you give us component classes instead of factories? Are you using a lib that only generates factories?
I guess we could have a <Route handlerFactory> prop. Then you could be explicit about the fact that you're giving us a factory, not a component class.
@mjackson Yep - using a lib that generates factories. A handlerFactory param seems like a good solution
people who don't use JSX and are told by the React docs to ALWAYS wrap your components with createFactory if you want to use them without JSX
Looking at this doc and related ones, they always tell you to do the wrapping inside the module that consumes the component (after import). So if you have a module or library that gives you a factory, it seems an anti-pattern to me and a step backwards.
Anyway, I'm not opposed to handlerFactory as a band-aid solution. But without factory.type there's no way to support transition hooks, or is there?
That lib should not generate factories, I don't want to add API to be defensive for people using anti-patterns defined by React itself.
You could make your own version of RouteHandler though. Or even monkey patch render in your app.
@rpflorence Is it a blessed pattern to wrap components into elements when components are given as properties instead of letting the user control it? I have a few modules that take components in the same way but the vibe I got from the react docs was to let the user do it themselves
I think users should always get a component, not a factory, no matter where.