Skip to content

Instantly share code, notes, and snippets.

@NorikDavtian
Created October 23, 2017 07:29
Show Gist options
  • Select an option

  • Save NorikDavtian/ede92145140ca5a505bbd2ea5fe25b19 to your computer and use it in GitHub Desktop.

Select an option

Save NorikDavtian/ede92145140ca5a505bbd2ea5fe25b19 to your computer and use it in GitHub Desktop.

JS Decorators Example for Redux Connect

In general, this would be used as follows:

class MyReactComponent extends React.Component {}

export default connect(mapStateToProps, mapDispatchToProps)(MyReactComponent);

However, because of how the decorator syntax works, this can be replaced with:

@connect(mapStateToProps, mapDispatchToProps)
export default class MyReactComponent extends React.Component {}

and get the exact same functionality.

Excerpts from: https://www.sitepoint.com/javascript-decorators-what-they-are/

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