ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Children이란?
    React 2019. 11. 19. 23:48
    • Section.js
    import React from "react";
    import PropTypes from "prop-types";
    import styled from "styled-components";
    
    import Section from "Components/Section";
    
    const Container = styled.div`
      padding: 0px 10px;
    `;
    
    const HomePresenter = ({ nowPlaying, popular, upcoming, loading, error }) =>
      loading ? null : (
        <Container>
          {nowPlaying && nowPlaying.length > 0 && (
            <Section title="Now Playing">
              {nowPlaying.map(movie => movie.title)}
            </Section>
          )}
          {upcoming && upcoming.length > 0 && (
            <Section title="Upcoming Movies">
              {upcoming.map(movie => movie.title)}
            </Section>
          )}
          {popular && popular.length > 0 && (
            <Section title="Popular Movies">
              {popular.map(movie => movie.title)}
            </Section>
          )}
        </Container>
      );
    
    HomePresenter.propTypes = {
      nowPlaying: PropTypes.array,
      popular: PropTypes.array,
      upcoming: PropTypes.array,
      loading: PropTypes.bool.isRequired,
      error: PropTypes.string
    };
    
    export default HomePresenter;
    
    • HomePresenter.js
    import React from "react";
    import PropTypes from "prop-types";
    import styled from "styled-components";
    
    // 이곳에서는 children을 활용한 영화 섹션을 나눈다.
    
    const Container = styled.div`
      :not(:last-child) {
        margin-bottom: 50px;
      }
    `;
    
    const Title = styled.span`
      font-size: 14px;
      font-weight: 600;
    `;
    
    const Grid = styled.div`
      margin-top: 25px;
    `;
    
    const Section = ({ title, children }) => (
      <Container>
        <Title>{title}</Title>
        <Grid>{children}</Grid>
      </Container>
    );
    
    Section.propTypes = {
      title: PropTypes.string.isRequired,
      children: PropTypes.oneOfType([
        PropTypes.arrayOf(PropTypes.node),
        PropTypes.node
      ])
    };
    
    export default Section;
    

     

    • children정의 : 

    'React' 카테고리의 다른 글

    Rendering Poster Component  (0) 2019.11.21
    Poster Component  (0) 2019.11.21
    #6 Presenters  (0) 2019.11.19
    let으로 할당 제거(Destructuring assignment)  (0) 2019.11.19
    Detail Container 2  (0) 2019.11.18

    댓글

Designed by Tistory.