React Lessons. Lesson 4. Homework.

Never miss a story from Soshace
Looks good!
Please enter correct name
Please enter correct email
Looks good!
Please confirm to subscribe!

a2a2543d-1502-4fac-9336-8f9627510105
Let’s talk about our homework. We shall notice, that in development of decorators / mixins all of logic in most cases work perfectly. It was implemented by us in the class. To complete our homework, the last thing that needs to be done is to put this logic into decorator and mixin. So that’s how our decorator will look like (src/decorators/oneOpen.js):

Decorators and mixins created to allow you to reuse your code, other words writing it once you will be able to use it in different places. What works today for articles will work tomorrow for comments, the authors or whatever. Therefore, when assigning the names of your entities create more universal (abstract) names. For example: openItem, openElement. To complete an optional part of our homework is enough to compare our received id with one we’ve  kept in the state. If so, this means that we need to close the article, to do this we can simply assign it to null, otherwise we’ll just change the id:

Our mixin (src/mixins/oneOpen.js) will be as follows:

Also ArticleList.js will be changed the following way:

ArticleListOld.js will look like this:

Please add following inscription in app.js, and delete import  of an  ArticleList:

Please compare our code with yours, and we will go further. Please check this repository for the right commits.

435258_8a75_3

We are looking forward to meeting you on our website soshace.com

Never miss a story from Soshace
Looks good!
Please enter correct name
Please enter correct email
Looks good!
Please confirm to subscribe!
Pavel Bragin 14 09 2016 Category:

Related articles

15.06.2019

5 Awesome JavaScript Conferences to Attend in 2019

With web development being an incredibly popular domain, there’s no shortage of relevant events, meetups, and cons for web developers to gather.>>>

Events
11.06.2019

Yarn Package Manager in 2019: Should We Keep on Comparing Yarn with Npm?

Yarn was created by Facebook, Exponent, Google, and Tilde to improve upon the package management workflow. In this article, we’ll explore Yarn>>>

Fundamentals
7.06.2019

10 Sorting Algorithms Interview Questions: Theory and Practice for 2019

Proficiency in algorithms is such an essential part of programming knowledge that it’s hard to imagine great remote developers without it. The>>>

Human Resources