Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 是否会将在children.map期间创建的组件重新命名?_Reactjs - Fatal编程技术网

Reactjs 是否会将在children.map期间创建的组件重新命名?

Reactjs 是否会将在children.map期间创建的组件重新命名?,reactjs,Reactjs,如果我有如下设置: const ChildComponent = React.memo((props) => { return (<>...</>); }); const ParentComponent = (props) => { return ( {React.Children.map(props.children, child => { return <div>{child}</div&

如果我有如下设置:

const ChildComponent = React.memo((props) => {
   return (<>...</>);
});

const ParentComponent = (props) => {
   return (
      {React.Children.map(props.children, child => {
         return <div>{child}</div>;
      )}
   );
}
const ChildComponent = React.memo((props) => {
   return (<p>{props.a}</p>);
}, (prev, next) => {
   if (prev.a === next.a) { console.log('memo'); return true; }
   console.log('no memo'); return false;
});

const ParentComponent = (props) => {
   return (
      {React.Children.map(props.children, child => {
         return <div>{child}</div>;
      )}
   );
}

const App = () => {
   return (
      <ParentComponent>
          <ChildComponent a='a'/>
          <ChildComponent a='b'/>
          <ChildComponent a='c'/>
      </ParentComponent>
   );
}
const ChildComponent=React.memo((道具)=>{
回报率(…);
});
常量ParentComponent=(道具)=>{
返回(
{React.Children.map(props.Children,child=>{
返回{child};
)}
);
}

假设
child.props
完全相同,则会将
child
记录下来,还是每次都会重新播放?

将设置更改为以下内容:

const ChildComponent = React.memo((props) => {
   return (<>...</>);
});

const ParentComponent = (props) => {
   return (
      {React.Children.map(props.children, child => {
         return <div>{child}</div>;
      )}
   );
}
const ChildComponent = React.memo((props) => {
   return (<p>{props.a}</p>);
}, (prev, next) => {
   if (prev.a === next.a) { console.log('memo'); return true; }
   console.log('no memo'); return false;
});

const ParentComponent = (props) => {
   return (
      {React.Children.map(props.children, child => {
         return <div>{child}</div>;
      )}
   );
}

const App = () => {
   return (
      <ParentComponent>
          <ChildComponent a='a'/>
          <ChildComponent a='b'/>
          <ChildComponent a='c'/>
      </ParentComponent>
   );
}
const ChildComponent=React.memo((道具)=>{
返回({props.a}

); },(上一页,下一页)=>{ if(prev.a==next.a){console.log('memo');返回true;} console.log('no memo');返回false; }); 常量ParentComponent=(道具)=>{ 返回( {React.Children.map(props.Children,child=>{ 返回{child}; )} ); } 常量应用=()=>{ 返回( ); }
我在控制台中看到了
memo
。无论如何,这似乎不是一个详尽的答案,但我认为这意味着它是有效的