Gitsunmin

TIL

TIL
(=Today I Learned)

How to check children in React Component

import React from 'react';

const ComponentA = ({ children }) => {
  let hello;
  React.Children.forEach(children, (child) => {
    console.log(child);
    /**
     * {
     * 		$$typeof: 	Symbol(react.element)
     * 		key		: 	component에 설정한 key
     * 		props	:	component에 설정한 props
     * 		ref		: 	component에 설정한 ref
     * 		type	: 	component의 정보를 담고있는 객체
     * }
     **/
  });

  return hello;
};