skip to Main Content

I am working on a John Smilga project, Comfy Store. I am attempting to destructure data from an API with the following code

let store = getStorageItem('store');
const setupStore = (products) => {
    store = products.map((product) => {
        const {
            id, 
            fields: { featured, name, price, company, colors, image:img },} = product;
        const image = img[0].thumbnails.large.url;
        return { id, featured, name, price, company, colors, image };
        
    });
    
    setStorageItem('store', store);
};
console.log(store);

When a console.log store this ids what I getscreen capture

Why I am getting all the properties I am asking for EXCEPT the company one?
And how to I get the Company one to show in the console?

This is what the data looks likedata

2

Answers


  1. You are returning an array of obj from that API, using map function,
    if you need the first one try getting the first one with [0]

    Login or Signup to reply.
  2. By the code you provided it’s hard to tell where and how you call setupStore function at all. Maybe you override values somewhere in-between

    The destructuring in this example should work normally, but this code is not enough to identify the issue

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search