인프런 영문 브랜드 로고
인프런 영문 브랜드 로고

인프런 커뮤니티 질문&답변

Kwangsic Hyun님의 프로필 이미지
Kwangsic Hyun

작성한 질문수

Slack 클론 코딩[실시간 채팅 with React]

오브젝트 전달관련 질문드립니다.

작성

·

142

0

강의 중 질문이 있어 글남깁니다.

 

모달 팝업을 열거나 할때, 아래와 같이 하위 컴포넌트에서 스테이스를 전달하여 모달을 닫는 방식으로 되어 있는것을 확인하였습니다.

상위 컴포넌트:

 
const [showCreateChannelModal, setShowCreateChannelModal] = useState(false);
 
<CreateChannelModal
        show={showCreateChannelModal}
        onCloseModal={onCloseModal}
        setShowCreateChannelModal={setShowCreateChannelModal}
      />

하위 컴포넌트 :

interface Props {
  show: boolean;
  onCloseModal: () => void;
  setShowCreateChannelModal: (flag: boolean) => void;
}
const CreateChannelModal: FC<Props> = ({ show, onCloseModal, setShowCreateChannelModal }) => {
...

 

이 방식을 활용하여  아래와 같이 하위 컴포넌트에서 사용자 정보인 IUser를 전달해보고자 했는데 자꾸 set이 안되고 빈 값만 출력이 되는데 어떻게 해야할지를 모르겠어서 문의드립니다.

 

const [User, setUser] = useState({});
 
<CreateChannelModal
        show={showCreateChannelModal}
        onCloseModal={onCloseModal}
        setUser={setUser}
      />

하위 컴포넌트 :

interface Props {
  show: boolean;
  onCloseModal: () => void;
  setUser: (u: IUser) => void;
}
const CreateChannelModal: FC<Props> = ({ show, onCloseModal, setUser}) => {
...

답변 1

0

제로초(조현영)님의 프로필 이미지
제로초(조현영)
지식공유자

setUser를 어떻게 사용하셨나요? 유저 정보를 전달하려면 user를 넘기는 게 맞지 않나요?

Kwangsic Hyun님의 프로필 이미지
Kwangsic Hyun

작성한 질문수

질문하기