做一个条件渲染组件 IF

71 阅读1分钟

代码实现:

const If = props => {
  const condition = props.condition || false;
  const positive = props.then || null;
  const negative = props.else || null;

  return condition ? positive : negative;
};

应用:

<If 
    condition={判断条件}
    then={}
    else={}
/>