What does the at symbol (@) do in ES6 javascript? (ECMAScript 2015)

I found the accepted answer was not enough to help me sort this out, so I’m adding a little more detail to help others who find this.

The problem is that it’s unclear exactly what is the decorator. The decorator in the example given is not just the @ symbol, it’s the @connect function. Simply put, the @connect function is decorating the CounterApp class.

And what is it doing in this case? It’s connecting the state.counter value to the props of the class. Remember that in redux the connect function takes two arguments: mapStateToProps and mapDispatchToProps. In this example, it’s taking only one argument – mapStateToProps.

I haven’t investigated this too much, but this appears to be a way to encapsulate your state-to-props and dispatch-to-props mappings so they accompany your components rather than being located in a different file.

Leave a Comment