Reader small image

You're reading from  React.js Essentials

Product typeBook
Published inAug 2015
Reading LevelIntermediate
PublisherPackt
ISBN-139781783551620
Edition1st Edition
Languages
Right arrow
Author (1)
Artemij Fedosejev
Artemij Fedosejev
author image
Artemij Fedosejev

Artemij Fedosejev is a technical lead living in London, United Kingdom. He is a self-taught web developer who has been a web developer since the early 2000s. Artemij earned his BSc in computer science from University College Cork, Ireland. He participated in the IGNITE Graduate Business Innovation Programme, where he built and launched a website that received the Most Innovative Project award. Artemij has played a key role in creating frontend architecture using React.js and Flux for various websites. Artemij created a number of open source projects, including Snapkite Engine, Snapkite Stream Client, and other projects.
Read more about Artemij Fedosejev

Right arrow

Refactoring the TweetList component


The TweetList component renders a list of tweets. Each tweet is a Tweet component that a user can click on to remove it from a collection. Does it sound like it could make use of CollectionActionCreators to you?

That's right, let's add the CollectionActionCreators module to it:

var CollectionActionCreators = require('../actions/CollectionActionCreators');

Then, we create the removeTweetFromCollection() callback function that will be called when a user clicks on a tweet image:

removeTweetFromCollection: function (tweet) {
  CollectionActionCreators.removeTweetFromCollection(tweet.id);
},

As you can see, it creates a new action through the removeTweetFromCollection() function by passing the tweet ID to it as an argument.

Finally, we need to make sure that removeTweetFromCollection() is actually called. In the getTweetElement() method, we check the following line:

var handleRemoveTweetFromCollection = this.props.onRemoveTweetFromCollection;

Now, we replace it with...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
React.js Essentials
Published in: Aug 2015Publisher: PacktISBN-13: 9781783551620

Author (1)

author image
Artemij Fedosejev

Artemij Fedosejev is a technical lead living in London, United Kingdom. He is a self-taught web developer who has been a web developer since the early 2000s. Artemij earned his BSc in computer science from University College Cork, Ireland. He participated in the IGNITE Graduate Business Innovation Programme, where he built and launched a website that received the Most Innovative Project award. Artemij has played a key role in creating frontend architecture using React.js and Flux for various websites. Artemij created a number of open source projects, including Snapkite Engine, Snapkite Stream Client, and other projects.
Read more about Artemij Fedosejev