0

I have a question about those 2 conditional statements as I think they are.

  1. [array]?.map() syntax my assumption it checks if the previous array has a value so in case it is empty it won't crash the app.

{context.somestate[props.someprops]?.map((someEl) => (
        <compnent key={someEl.id}  />
      ))}
  1. a chunk from a code that is used to add an item in to a state in react in the reducer file, my assumption here it is also checking for empty value ?

case ADD_SOME_ITEM:

      return {
        ...state,
        someItems: {
          ...state.someItems,
          [action.index]: [
            ...(state.someItems[action.index] ?? []),
            { id: action.id }
          ]
        }
Jackhammer
  • 744
  • 3
  • 10

0 Answers0