React入门,无法渲染通过道具的页面

问题描述 投票:0回答:1

我设置了两个对象来模拟一些数据。我想在页面上打印两个元素,但是codePen不会显示任何错误,为什么它不会输出到页面上。

应用程序应输出两个h1元素,它们与我分配给的对象相对应。不要以为我需要在那兴起任何州。仅使用obj和obj2中的道具

谢谢。

<div id="root">
</div>
let obj = {
  firstName: "Bobby",
  lastName: "Lee",
};

let obj2 = {
  firstName: "Priscilla",
  lastName: "Young",
};

function Element(props) {
  return (
  <h1> Welcome back {props.identification.firstName} {props.identification.lastName} !</h1>;
  );
}


function App() {
  return (
    <div>
      <Element identification={obj} />
      <Element identification={obj2} />
    </div>
  );
}


ReactDOM.render(<App />, document.getElementById('root'));
javascript html reactjs
1个回答
1
投票

尝试此

function Element(props) {
  return (
  <h1> Welcome back {props.identification.firstName} {props.identification.lastName} !</h1>
  );
}
© www.soinside.com 2019 - 2024. All rights reserved.