Last active
December 2, 2017 14:06
-
-
Save bultas/f0c178443e0f865bb30a3471472df724 to your computer and use it in GitHub Desktop.
Redux Connect use like children-as-func instead of HOC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { createElement } from 'react'; | |
import { render } from 'react-dom'; | |
import { Provider, connect } from 'react-redux'; | |
import { store } from 'store'; | |
const TypeConnector = connect(({ router: { type } }) => { | |
return { | |
type | |
}; | |
})(function Connector({ type, children }) { | |
return children({ type }); | |
}); | |
// Without JSX | |
render( | |
createElement( | |
Provider, | |
{ store }, | |
createElement(TypeConnector, null, ({ type }) => { | |
return createElement('div', null, type); | |
}) | |
), | |
document.querySelector('#app') | |
); | |
// With JSX | |
render( | |
<Provider store={store}> | |
<TypeConnector> | |
{function NamedComponent({ type }) { | |
return <div>{type}</div>; | |
}} | |
</TypeConnector> | |
</Provider>, | |
document.querySelector('#app') | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment