children prop의 사용 및 prototype
children prop의 사용 및 prototype
React에서는 children이라는 reserved prop이 존재한다.
"Children are the components that are placed inside the component."란다.
const Section = ({ title, children }) => ( {title} {children} );
import Section from "Section" const HomePresenter = ({ nowPlaying, popular, upComing, error, loading }) => loading ? null : ( {upComing && upComing.length > 0 && ( {upComing.map(movie => movie.title)} )} );
다음과 같은 방식으로 chideren을 통해 Grid로 들어간다.
또한, 관습적으로 children Proptypes은 다음과 같이 적어 준다.
PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node])
실제 코드로 작성하면 다음과 같이 보인다.
import React from "react" import PropTypes from "prop-types" const Section = ({ title, children }) => (); Section.prototype = { title: PropTypes.string.isRequired, childeren: PropTypes.oneOfType([ PropTypes.arrayOf(PropTypes.node), PropTypes.node ]) }
from http://darrengwon.tistory.com/161 by ccl(A) rewrite - 2020-03-17 17:20:16
댓글
댓글 쓰기