Mt style was different from yours

Screenshot (92)|690x451

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 :upside_down_face: :stuck_out_tongue_winking_eye:

I wanna know what advantage Mosh’s has over mine

section : 4 (composing components)
lesson 22

thanks :star_struck:

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.

1 Like

whoaaa :thinking: :exploding_head: I did not think of that thanks @rob

i really appreciate

1 Like