0

есть объект

const columnsForWidgets = {
        firstCol: {
            name: 'firstCol',
            items: ComponentsWidgets.ComponentsArr,
        },
        secCol: {
            name: 'secCol',
            items: ComponentsWidgets.ComponentsArr2,
        },

        thirdCol: {
            name: 'thirdCol',
            items: ComponentsWidgets.ComponentsArr3,
        },
        fourthCol: {
            name: 'fourthCol',
            items: ComponentsWidgets.ComponentsArr4,
        },
    };

В ключе items лежит еще массив типа

[
    {
      id: 'MttrWidget',
      show: true,
      comp: () => <MttrWidget />,
    },
    {
      id: 'BotCount',
      show: true,
      comp: () => <BotCount />,
    },
]

Они отрисовывают у меня виджеты на странице. Как добраться и изменить show на false в состоянии ? т.к они отрисовываются только если show true

1 ответ 1

0

Полагаю есть и более изящные решения.

По быстрому придумал что-то такое

const keysObj = Object.keys(columnsForWidgets);

const result = keysObj.map(key => {
    const column = columnsForWidgets[key];
    const items = column.items.map(item => ({
        ...item,
        show: true
    }))
    
    return {
        ...column,
        items
    }
})

пример

1
  • Спасибо большое, взял на заметку )
    – Feyoayo
    14 июл 2021 в 10:40

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.