Skip to content

Instantly share code, notes, and snippets.

@wuct
Last active April 23, 2016 09:29
Show Gist options
  • Save wuct/46682c7c2f6e3536162a to your computer and use it in GitHub Desktop.
Save wuct/46682c7c2f6e3536162a to your computer and use it in GitHub Desktop.
Recopose Compnents Syntax
// 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)
@wuct
Copy link
Author

wuct commented Mar 10, 2016

2的優點,可單獨 export Component

export const Component;
export default compose(HOCs)(Component)

@wuct
Copy link
Author

wuct commented Mar 10, 2016

改良的 2,HOC 搬到前面
缺點 Component name 出現兩次,container name 出現兩次

export const container = compose(
  // HOC
)

export const Component = ({
  // ...destructured props
}) =>
  // react element

export default container(Component)

@lulalachen
Copy link

寫4的話感覺未來只要獨立一個component就盡量開新的file
保持一個file一個component的原則會比較好閱讀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment