Last active
July 17, 2020 22:43
-
-
Save ide/41a6530a0b606545c55f to your computer and use it in GitHub Desktop.
Moving Redux state mapper into a component
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
// Trying out a new syntax. It is: | |
// | |
// - not magical except for the DecoratedComponent bit | |
// - communicates that it returns props | |
// - ...that are computed from Redux data | |
// - resembles familiar functions like getInitialProps | |
// - nice aesthetically | |
@connect(data => X.DecoratedComponent.getDataProps(data)) | |
export default class X extends React.Component { | |
static getDataProps(data) { | |
return { | |
propA: data.store.fieldA, | |
propB: data.store.fieldB, | |
}; | |
} | |
} | |
// instead of | |
@connect(data => ({ | |
propA: data.store.fieldA, | |
propB: data.store.fieldB, | |
})) | |
export default class X extends React.Component { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment