React에서는 원하는 동작을 캡슐화하는 Component를 만들 수 있습니다.

이렇게 하면 애플리케이션의 상태에 따라서 Component 중 몇 개만을 렌더링할 수 있습니다.

< 컴포넌트가 렌더링하는 것을 막기 >

가끔 다른 Component에 의해 렌더링될 때 Component 자체를 숨기고 싶을 때가 있을 수 있습니다.

이때는 렌더링 결과를 출력하는 대신 null을 반환하면 해결할 수 있습니다.

function WarningBanner(props) {
  if (!props.warn) {
    return null; // null
  }

  return (
    <div className="warning">
      Warning!
    </div>
  );
}

class Page extends React.Component {
	// ...(생략)

  render() {
    return (
      <div>
        <WarningBanner warn={this.state.showWarning} /> // null or expression
        <button onClick={this.handleToggleClick}>
          {this.state.showWarning ? 'Hide' : 'Show'}
        </button>
      </div>
    );
  }
}

Component의 render 메서드로부터 null 을 반환하는 것은 생명주기 메서드 호출에 영향을 주지 않습니다. 그 예로 componentDidUpdate() 는 계속해서 호출되게 됩니다.