目前我有以下
methodName = () => {
const {
collectionOfComponents
...
...
} = this.props;
return (
<Wrapper1>
{collectionOfComponents.map((oneComponent, index) => (
<Wrapper2
..props
>
{oneComponent.component}
</Wrapper2>
)}
</Wrapper1>
);
};
对于collectionOfComponents,我传递了以下内容
collectionOfComponents={[
<ComponentOne prop1... prop2... />,
<ComponentOne prop1... prop2... />,
<ComponentTwo prop1... prop2... />
]}
有没有办法确定何时ComponentTwo
通过,以便我可以执行不同的渲染。我不知道该怎么做
编辑对不起,应该说清楚,但我不想改变地图中的渲染方法我正在寻找一个单独的函数来首先检查componentTwo
数组中是否存在,然后(也许)使用第三个调用两个方法之一,这将是两个不同的返回方法。然后我将在 render 方法中调用该函数