I created a stateless functional class with a toggle function , but Mosh’s own was quite different from mine despite we had the same result
I wanna know what advantage Mosh’s has over mine
section : 4 (composing components)
lesson 22
thanks
I created a stateless functional class with a toggle function , but Mosh’s own was quite different from mine despite we had the same result
I wanna know what advantage Mosh’s has over mine
section : 4 (composing components)
lesson 22
thanks
Your Like class is not stateless because it contains a state with a ‘liked’ property. Mosh’s code is better because he creates a stateless functional component. There’s no state. It gets everything it needs for the render method passed in via props. The main benefit of this is that the movies array serves as the single source of truth for what is liked/unliked.
Also, in your class component, you toggle the the status of the heart icon internally. What would you do if another part of your app needed to know if a specific movie was liked/unliked? There’s no way to know. How would your component work if you needed to pass the like information back up to the server? If you call back out to another component like Mosh does, you can handle all the networking in one place.
whoaaa I did not think of that thanks @rob
i really appreciate