React native 使用属性传递到组件

React native 使用属性传递到组件,react-native,React Native,我有一个用于绘制玩家档案的组件,我需要传入两个变量中的一个;男人或女人 这只需导入组件并调用 <PlayerProfiles typeOfProfile='Men'/> 它正在调用的组件被设置为这样 const PlayerProfiles = (typeOfProfile) => { const [isLoading, setLoading] = useState(true); const [data, setData] = useState([]); functio

我有一个用于绘制玩家档案的组件,我需要传入两个变量中的一个;男人或女人

这只需导入组件并调用

<PlayerProfiles typeOfProfile='Men'/>

它正在调用的组件被设置为这样

const PlayerProfiles = (typeOfProfile) => {
const [isLoading, setLoading] = useState(true);
const [data, setData] = useState([]);

function playertype(val) {
    return 'https://s2.eu-west-1.amazonaws.com/xxxx.json';;
}

useEffect(() => {
fetch(playertype(typeOfProfile))
  .then((response) => response.json())
  .then((json) => {
    setData(json)
    })
  .catch((error) => console.error(error))
  .finally(() => setLoading(false));
}, []);

return (
<View style={styles.body}>
  <View style={styles.topscroll}>
  {isLoading ? <ActivityIndicator/> : (
    <FlatList
      data={data.filter(data => data.Sex == 'Men')}
constplayerprofiles=(profile的类型)=>{
const[isLoading,setLoading]=useState(true);
const[data,setData]=useState([]);
函数播放类型(val){
返回'https://s2.eu-west-1.amazonaws.com/xxxx.json';;
}
useffect(()=>{
获取(playertype(typeOfProfile))
.then((response)=>response.json())
。然后((json)=>{
setData(json)
})
.catch((错误)=>console.error(错误))
.最后(()=>setLoading(false));
}, []);
返回(
{正在加载?:(
data.Sex=='man')}
我面临的挑战是,当我想在
data={data.filter(data=>data.Sex==typeOfProfile)}
中使用typeOfProfile值而不是硬编码的'Men'时,它不会将值作为字符串读取


我尝试过使用JSON.stringify(typeOfProfile),但它也会返回属性的名称(typeOfProfile)。在我去掉所有非值部分之前,我的问题是什么是将值传递给typeOfProfile的最简单方法?

未正确使用
typeOfProfile
属性

constplayerprofiles=(道具)=>{
const typeOfProfile=props.typeOfProfile;
const[isLoading,setLoading]=useState(true);
const[data,setData]=useState([]);
或者你可以重组道具

constplayerprofiles=({typeOfProfile})=>{
const[isLoading,setLoading]=useState(true);
const[data,setData]=useState([]);

请参阅。

man的复数形式是“men”-而不是“mens”…谢谢@str4605,我是个新来的土生土长的人(字面意思是2周),所以仍然遗漏了一些基本内容。。。