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
。无论如何,这似乎不是一个详尽的答案,但我认为这意味着它是有效的