리액트 전역 변수 (방법2)

2021. 9. 28. 13:47웹랩/JavaScript

반응형

App.js

import MyProfile from "./components/MyProfile";

const iam = {
  lastName: "Hong",
  firstName: "GilDong",
  koName: "홍길동",
};

return (
  <div className="App">
    <MyProfile iam={iam} />
  </div>
)

 

MyP...js

class MyProfile extends Component {
  constructor(props) {
    super(props);
    this.iam = props.iam;
  }
  render() {
    return (
      <section id="MyProfile">
        <h2>
          Who am I <em> {this.iam.lastName}입니다</em>
반응형