Hello! On air bnb, on the product cards there is a component"Save to Favorites(liked)"
How to implement it? I understand that we have the main state where the state of the entire application is stored + an array of products(product cards)...when I click on like, I change false to true of the product card itself or just the like component? Like button is a separate component?
  • The question is what are you doing or how is airbnb implemented? You can do whatever you like, and as implemented in airbnb - who knows, in the browser, the compiled and minimized version. – Intellectual28 Jan 15 '19 at 13:11

2 Answers 2

the option"when clicking on like, I change false to true of the item card itself" - OK(meaning, you change one of the properties in the object with information about this ad, for example: isFavorite: true)

In a real application, the request still flies to the server, so that the client has marked such and such an object as a favorite.
  • How can I change the property of the product when I click on the"like" button?
    state={
        savedProducts:[],
        products:[
          {
            id: 1,
            title:'Product One',
            saved: false
          },
          {
            id: 2,
            title:'Product Two',
            saved: false
          },
          {
            id: 3,
            title:'Product Three',
            saved: false
          }
        ]
      };
    – Comfortable43 Jan 15 '19 at 14:08
Separate.Or not separate - as you wish.I prefer maximum decomposition.