[React] props 넘겨주기

0

리액트

목록 보기
2/14
post-thumbnail

🙆🏻‍♀️ [React] props 넘겨주기 🙆🏻‍♀️

Children 컴포넌트에 props 넘겨주기👶🏻

// Common container
import React from "react";
import { Layout } from "antd";

const { Content } = Layout;

const CommonContainer = ({ children }) => {
  return (
    <Layout style={{ minHeight: "100vh" }}>
      <Content>
    	{React.cloneElement(children, { props:"someProps" })}
      </Content>
    </Layout>
	);
  };

export default CommonContainer;
// Content layout
import React from "react";

import CommonContainer from "./CommonContainer";
import CotentComponent from "./Content";

const ContentLayout = () => {
  return (
    <CommonContainer>
      <CotentComponent />
    </CommonContainer>
  );
};

export default ContentLayout;
// Content
import React from "react";

const ContentLayout = (props) => {
  return ( 
  // someProps 출력...
    {props}
  );
};

export default ContentLayout;
profile
당당하게 외치고 싶어요. "나, 「프런트엔드 개발자」야" 라고...😏

2개의 댓글

comment-user-thumbnail
2021년 9월 16일

똑똑!

1개의 답글