Created
August 5, 2016 15:39
-
-
Save LucaColonnello/8f52946193977fcd6727318c2e727513 to your computer and use it in GitHub Desktop.
withRender 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, { Component } from 'react'; | |
import { compose } from 'redux'; | |
import { connect } from 'react-redux'; | |
// supposed to receive a class and return a new function (curryed) that | |
// if called add a render function to the received class, | |
// rendering the received component passing down all the props | |
import { withRender } from './utils'; | |
// container class with event handler and action creator dispatch | |
class AContainer extends Component { | |
onBtnClick() {} | |
componentDidMount(){} | |
} | |
// factory of AContainer, composed by redux connect and withRender | |
export const AContainerWithRender = compose( | |
connect(() => {}, {}), | |
withRender(AContainer) | |
) | |
// default version using A as dumb component | |
export default AContainerWithRender(A); | |
// usage in another file with default render | |
import React from 'react'; | |
import AContainer from './AContainer'; | |
React.render(<AContainer />, ...); | |
// usage in another file with custom render | |
import React from 'react'; | |
import { AContainerWithRender } from './AContainer'; | |
const AContainer = AContainerWithRender((props) => ( | |
<div>My custom renderer</div> | |
)); | |
React.render(<AContainer />, ...); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment