Skip to content

Instantly share code, notes, and snippets.

@ide
Last active July 17, 2020 22:43
Show Gist options
  • Save ide/41a6530a0b606545c55f to your computer and use it in GitHub Desktop.
Save ide/41a6530a0b606545c55f to your computer and use it in GitHub Desktop.
Moving Redux state mapper into a component
// 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