React 根据 组件名称动态加载组件

const Component = ({ is, children, ...restProps }) => {
  const Tag = require("antd")[is];

  if (!Tag) return false;

  return <Tag {...restProps}>{children}</Tag>;
};

export default Component;

  

<Component
          is="Switch"
          checkedChildren="开启"
          unCheckedChildren="关闭"
          defaultChecked
          onClick={() => console.log(222)}
        >
          122
        </Component>

  

posted @ 2020-11-27 11:33  winyh  阅读(1653)  评论(0编辑  收藏  举报