Last active
September 25, 2015 20:49
-
-
Save stoeffel/20d3f9a820304fd25ee0 to your computer and use it in GitHub Desktop.
React compose thisless components
This file contains 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 { | |
compose, | |
initialState, | |
didMount | |
} from 'react'; | |
export const MyComponent = compose( | |
initialState( () => { | |
return { | |
hidden: true | |
}; | |
}, | |
connectToStores([Store1, Store2]), // higher-order component pattern | |
didMount( (props, { setState, state }) => { | |
// do stuff | |
}, | |
( props, { setState, state } ) => | |
<div> | |
{ /* ... */ } | |
</div> | |
) | |
); | |
// same as | |
let Foo = ({ props, { setState, state }}) => ( | |
<div> | |
{/* ...*/} | |
</div> | |
); | |
Foo = initialState(() => { | |
return { hidden: true } | |
}, Foo); |
Author
stoeffel
commented
Sep 25, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment