A
A
Anastasia2020-11-26 09:50:32
React
Anastasia, 2020-11-26 09:50:32

How to access the field of an object in React if it comes as a response from the backend and is initially an empty object?

item is an object that is empty at the time of rendering, so it does not yet have a parentNode field, so an error is immediately thrown

renderValue={(value, item, selectedElement) => {
        console.log(`${item.parentNode.label} ${selectedElement}`)
      }}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir, 2020-11-26
@KnopkaNen

item?.parentNode?.label

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question