Why does React.Children.map redraw in react

The

code is as follows: why does the whole component (including subcomponents) re-mount when currentItem.isLeaf changes

return React.Children.map([0,1,2,3,4,5,6], (Child, index) => {
      const ChildNode = currentItem.isLeaf === "1" ?
        AComponent :
        BComponent;

      return React.createElement(ChildNode,
        {
          amount: 5,
          index,
          key: `level-${index}`,
        }
      )
    })
Mar.24,2021

the answer is type is different .

The function signature of

React.createElement is React.createElement (type, props, children) .

React when doing dom diff , the first thing to judge is that type, will render again if the type is inconsistent (remove and then append).

when the subject currentItem.isLeaf changes, the corresponding type changes, so it will be re-rendered.

Menu