강의 중 질문이 있어 글남깁니다.
모달 팝업을 열거나 할때, 아래와 같이 하위 컴포넌트에서 스테이스를 전달하여 모달을 닫는 방식으로 되어 있는것을 확인하였습니다.
상위 컴포넌트:
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}) => {
...