Learn How to solve Machine coding step by step | 2 year experienced

Поделиться
HTML-код
  • Опубликовано: 21 янв 2025

Комментарии • 5

  • @madhanravi4365
    @madhanravi4365 4 месяца назад +2

    Very helpful sir

  • @SurajVishwakarma-dm7ib
    @SurajVishwakarma-dm7ib 4 месяца назад +1

    Could you explain the scenario in which we need to pass key in fragment and how to do so with cose example

    • @IshanRohatgiyt
      @IshanRohatgiyt 4 месяца назад +1

      {items.map((item, index) => (
      {item}
      Description for {item}
      ))}

    • @madhanravi4365
      @madhanravi4365 4 месяца назад +1

      You can pass a key to fragments, but you need to use the full syntax instead of the shorthand if you want to assign a key. The shorthand syntax does not support the key attribute.
      Here’s how you can do it:
      jsx
      Copy code
      {items.map((item, index) => (
      {item}
      Description for {item}
      ))}
      Key Points:
      Shorthand : Cannot take a key attribute.
      Full : Allows you to pass a key attribute, making it useful when iterating over a list and you need to group elements without adding extra nodes to the DOM.
      Using React.Fragment with a key is particularly helpful in lists where you want to avoid adding unnecessary wrapper elements but still need to uniquely identify each fragment in a list.