[React Native] Props 삽질..

Tim Lee·2021년 8월 15일
0

등록 된 장치의 라벨 명을 부모로 부터 Props로 받아와서 보여주는 것을 구현하는 데, 계속 Props 로 받아온 값이 Undefined 로 나온다.

그 원인은 너무 심플했다.

변수를 선언 후 함수 안에서 값을 할당 하고, 함수 안에서만 로그를 찍어서 정상적이라고 오해한 것..

아래와 같이 변수 값이 설정 되도록 잡아주고

const [deviceLabelName, setDeviceLabelName] = useState('');

const pressButton = () => {
setModalVisible(true);
console.log('전달할 장치3:' + deviceName);
setDeviceLabelName(deviceName);
};

장치 쪽에 Props로 넣어주니

   <BottomSheet
    modalVisible={modalVisible}
    setModalVisible={setModalVisible}
    deviceName={deviceLabelName}
  />

정상적으로 장치 라벨 입력 표시

하나씩 확실하게 짚고 넘어가자.

profile
마흔 한살에 시작한 개발

0개의 댓글

관련 채용 정보

Powered by GraphCDN, the GraphQL CDN