2017-02-21 5 views
1

소품으로 React Native의 맞춤식 무국적 구성 요소에 이미지 원본과 제목을 보내려고합니다. (imageSource 및 제목)반응 네이티브로 상태 비 저장 구성 요소에 소품 보내기

props.imageSource 줄 오류가 발생했습니다, 도움을 주셨습니다.

const MainPageButton = (props) => { 

    var imageSource = require({props.imageSource}); 

    return (
     <TouchableOpacity> 
      <Image source={imageSource} /> 
      <Text>{props.title}</Text> 
     </TouchableOpacity> 
    ) 
} 

답변

1

대신 object destructuring를 사용해야합니다 :

const MainPageButton = ({imageSource, title}) => { 

    var imageSource = require(imageSource); 

    return (
    <TouchableOpacity> 
     <Image source={imageSource} /> 
     <Text>{title}</Text> 
    </TouchableOpacity> 
) 
} 
1

교체

var에 imageSource = 필요 ({props.imageSource}); 여기에 문제의 코드는

var에 필요 imageSource = (props.imageSource)와

; 당신이

를 사용하는

props.imageSource 충분히 당신 문자열을 줄 것이다

관련 문제