O'Reilly logo

ReactJS by Example - Building Modern Web Applications with React by Prathamesh Sonpatki, Vipul A M

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Flux actions

"Now we need to define the actions types that we are going to refer to as constants at various places, such as sending the type from Actions to store, and in our store, deciding what action type has been passed to store to take appropriate actions.

//SocialConstants.js
var keyMirror = require('keymirror');

module.exports = keyMirror({
  FILTER_BY_TWEETS: null,
  FILTER_BY_REDDITS: null,
  SYNC_TWEETS: null,
  SYNC_REDDITS: null

});

"Here, we are using the https://github.com/STRML/keyMirror package to create keys and values for the object based on the keys. This will convert into object similar to below."

{
FILTER_BY_TWEETS: 'FILTER_BY_TWEETS', 
…
}

"This is handy when adding new keys to not repeat the same contents again."

"We can now start using ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required