Last active
April 23, 2016 09:29
-
-
Save wuct/46682c7c2f6e3536162a to your computer and use it in GitHub Desktop.
Recopose Compnents Syntax
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
// 1 | |
// cons:the component name appears twice | |
const Component = compose( | |
// HOC | |
)(({ | |
// ...destructured props | |
}) => | |
// react element | |
); | |
export default Component; | |
// 2 | |
// cons: | |
// - The component name appears twice. | |
// - The HOC apperas after the componet. | |
const Component = ({ | |
// ...destructured props | |
}) => | |
// react element | |
export default compose( | |
// HOC | |
)(Component); | |
// 3 | |
// cons:introduce setDisplayname | |
export defacult compose( | |
setDisplayname('Component'), | |
// HOC | |
)(({ | |
// ...destructured props | |
}) => | |
// react element | |
); | |
// 4 | |
// cons:Both the component name and the container name appears twice. | |
export const container = compose( | |
// HOC | |
) | |
export const Component = ({ | |
// ...destructured props | |
}) => | |
// react element | |
export default container(Component) |
改良的 2,HOC 搬到前面
缺點 Component name 出現兩次,container name 出現兩次
export const container = compose(
// HOC
)
export const Component = ({
// ...destructured props
}) =>
// react element
export default container(Component)
寫4的話感覺未來只要獨立一個component就盡量開新的file
保持一個file一個component的原則會比較好閱讀
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
2的優點,可單獨 export Component