Properties 将道具发送到react native中的无状态组件

Properties 将道具发送到react native中的无状态组件,properties,react-native,components,Properties,React Native,Components,我正在尝试将图像源和标题作为道具发送到React Native中定制的无状态组件。(图片来源和标题) props.imageSource行导致错误,欢迎提供帮助。以下是相关代码: const MainPageButton = (props) => { var imageSource = require({props.imageSource}); return ( <TouchableOpacity> <Image s

我正在尝试将图像源和标题作为道具发送到React Native中定制的无状态组件。(图片来源和标题)

props.imageSource行导致错误,欢迎提供帮助。以下是相关代码:

const MainPageButton = (props) => {

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

    return (
        <TouchableOpacity>
          <Image source={imageSource} />
          <Text>{props.title}</Text>
        </TouchableOpacity>
    )
}
const MainPageButton=(道具)=>{
var imageSource=require({props.imageSource});
返回(
{props.title}
)
}
您应该改用:

const MainPageButton=({imageSource,title})=>{
var imageSource=需要(imageSource);
返回(
{title}
)
}
更换

var imageSource=require({props.imageSource})

var imageSource=require(props.imageSource)

imageSource将为您提供足够的字符串供您使用

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

  var imageSource = require(imageSource);

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