首页 > 解决方案 > 反应自定义组件未呈现

问题描述

*自定义组件未在 UI 上呈现,还请注意,我有 id 元素:root

function CComponent(prop) {
  const element = (
    <div className="container">
      <div className={prop.classname}>{prop.content}</div>
    </div>
  );

  return element;
}

const helloElement = (
  <CComponent>{{ classname: "xyz", content: "helloWorld" }}</CComponent>
);

console.log(helloElement);
ReactDOM.render(helloElement, document.getElementById("root"));

标签: javascriptreactjs

解决方案


您需要像这样将道具传递给组件:

const helloElement = <CComponent classname='xyz' content='helloWorld' />

推荐阅读