currying looks like an easier way (and even easier with recompose / withProps)
const getComponentWithProps = (props) => (location, cb) => { const Component = ;
UPDATE
CAUTION: PERFORMANCE my version is just the answer to the sugar diagnosis, and I suppose it has the same problems: it causes a complete redistribution of components when redirecting.
this is due to the re-arrangement of the component using Enhancer for each new location that generates a new component with each redirection.
As a quick fix, I decided to cache all the improvements in weak maps. in my case it looks like
const getOrAdd = (map) => (value = Function.prototype) => (key) => map.get(key) || ( map.set( key, value(), ) && map.get(key) ); const componentsMap = new WeakMap(); export const getEnhancedMap = getOrAdd(componentsMap)(() => new WeakMap()); export const getEnhancedComponent = ( component, enhancer, ) => { const enhancedMap = getEnhancedMap(component); return getOrAdd(enhancedMap)(() => enhancer(component))(enhancer); }
source share