Reactjs undefined不是本机对象(';evaluation props.user.map';)

Reactjs undefined不是本机对象(';evaluation props.user.map';),reactjs,react-native,Reactjs,React Native,不知什么原因,当我试图映射通过另一个组件传递的状态时,我得到这个未定义的错误不是对象('evaluation props.user.map'),我不知道为什么 以下是我了解该州的情况: import React, { Component } from "react"; import { Button, View, Text, Image } from "react-native"; export class FakeInfo extends Component { constructor(

不知什么原因,当我试图映射通过另一个组件传递的状态时,我得到这个未定义的错误不是对象('evaluation props.user.map'),我不知道为什么

以下是我了解该州的情况:

import React, { Component } from "react";
import { Button, View, Text, Image } from "react-native";

export class FakeInfo extends Component {
  constructor(props) {
    super(props);
    this.state = {
      user: [
        {
          image: "Food",
          name: "Thomas King",
          Age: "23",
          description: "I am looking to meet new people",
          location: "South Carolina",
        },
      ],
    };
  }

  render() {
    return (
      <View>
        <View>
          {this.state.user.map((item) => (
            <Text>{item.name}</Text>
          ))}
        </View>
      </View>
    );
  }
}
export default FakeInfo;
import React,{Component}来自“React”;
从“react native”导入{按钮、视图、文本、图像};
导出类FakeInfo扩展组件{
建造师(道具){
超级(道具);
此.state={
用户:[
{
图片:“食物”,
姓名:“托马斯·金”,
年龄:"23岁",,
描述:“我希望结识新朋友”,
地点:“南卡罗来纳州”,
},
],
};
}
render(){
返回(
{this.state.user.map((项)=>(
{item.name}
))}
);
}
}
导出默认FakeInfo;
这里是我映射状态的地方,也是我获取错误的地方:

import React, { Component } from "react";
import { Button, View, Text, Image } from "react-native";
import FakeInfo from "../UserPage/FakeProfileInfo";

const ViewProfile = (props) => (
  <View>
    {props.user.map((item) => (
      <Text>{item.name}</Text>
    ))}
  </View>
);

export default ViewProfile;
import React,{Component}来自“React”;
从“react native”导入{按钮、视图、文本、图像};
从“./UserPage/FakeProfileInfo”导入FakeInfo;
const ViewProfile=(道具)=>(
{props.user.map((项)=>(
{item.name}
))}
);
导出默认视图配置文件;

您真的在
ViewProfile
道具中发送“用户”吗

如果您使用ES6,我建议您这样写:

const ViewProfile=({user=[]})=>(
{props.user.map((项)=>(
{item.name}
))}
);

const ViewProfile=(道具)=>(
{props.user&&props.user.map((项)=>(
{item.name}
))}
);
使用它:

const ViewProfile = (props) => (
  <View>
    {props.user && props.user.map((item) => (
      <Text>{item.name}</Text>
    ))}
  </View>
);

const Page = (props) => (
  <View>
    <ViewProfile user={[{
          name: "Thomas King",
          Age: "23",
        }]} />
  </View>
);


const ViewProfile=(道具)=>(
{props.user&&props.user.map((项)=>(
{item.name}
))}
);
常量页面=(道具)=>(
);

您真的在
ViewProfile
道具中发送“用户”吗

如果您使用ES6,我建议您这样写:

const ViewProfile=({user=[]})=>(
{props.user.map((项)=>(
{item.name}
))}
);

const ViewProfile=(道具)=>(
{props.user&&props.user.map((项)=>(
{item.name}
))}
);
使用它:

const ViewProfile = (props) => (
  <View>
    {props.user && props.user.map((item) => (
      <Text>{item.name}</Text>
    ))}
  </View>
);

const Page = (props) => (
  <View>
    <ViewProfile user={[{
          name: "Thomas King",
          Age: "23",
        }]} />
  </View>
);


const ViewProfile=(道具)=>(
{props.user&&props.user.map((项)=>(
{item.name}
))}
);
常量页面=(道具)=>(
);
您没有在“FakeInfo”中使用“ViewProfile”,反之亦然。试试这个:

视图配置文件

import React, { Component } from "react";
import { Button, View, Text, Image } from "react-native";

const ViewProfile = (props) => (
  <View>
       <Text>{props.user.name}</Text>
  </View>
);

export default ViewProfile;
import React,{Component}来自“React”;
从“react native”导入{按钮、视图、文本、图像};
const ViewProfile=(道具)=>(
{props.user.name}
);
导出默认视图配置文件;
FakeInfo

import React, { Component } from "react";
import { Button, View, Text, Image } from "react-native";
import ViewProfile from '{ViewProfilePath}';

export class FakeInfo extends Component {
  constructor(props) {
    super(props);
    this.state = {
      user: [
        {
          image: "Food",
          name: "Thomas King",
          Age: "23",
          description: "I am looking to meet new people",
          location: "South Carolina",
        },
      ],
    };
  }

  render() {
    return (
      <View>
        <View>
          {this.state.user.map((item, key) => <ViewProfile user={item} key={key} />)}
        </View>
      </View>
    );
  }
}
export default FakeInfo;
import React,{Component}来自“React”;
从“react native”导入{按钮、视图、文本、图像};
从“{ViewProfilePath}”导入ViewProfile;
导出类FakeInfo扩展组件{
建造师(道具){
超级(道具);
此.state={
用户:[
{
图片:“食物”,
姓名:“托马斯·金”,
年龄:"23岁",,
描述:“我希望结识新朋友”,
地点:“南卡罗来纳州”,
},
],
};
}
render(){
返回(
{this.state.user.map((项,键)=>)}
);
}
}
导出默认FakeInfo;
您没有在“FakeInfo”中使用“ViewProfile”,反之亦然。试试这个:

视图配置文件

import React, { Component } from "react";
import { Button, View, Text, Image } from "react-native";

const ViewProfile = (props) => (
  <View>
       <Text>{props.user.name}</Text>
  </View>
);

export default ViewProfile;
import React,{Component}来自“React”;
从“react native”导入{按钮、视图、文本、图像};
const ViewProfile=(道具)=>(
{props.user.name}
);
导出默认视图配置文件;
FakeInfo

import React, { Component } from "react";
import { Button, View, Text, Image } from "react-native";
import ViewProfile from '{ViewProfilePath}';

export class FakeInfo extends Component {
  constructor(props) {
    super(props);
    this.state = {
      user: [
        {
          image: "Food",
          name: "Thomas King",
          Age: "23",
          description: "I am looking to meet new people",
          location: "South Carolina",
        },
      ],
    };
  }

  render() {
    return (
      <View>
        <View>
          {this.state.user.map((item, key) => <ViewProfile user={item} key={key} />)}
        </View>
      </View>
    );
  }
}
export default FakeInfo;
import React,{Component}来自“React”;
从“react native”导入{按钮、视图、文本、图像};
从“{ViewProfilePath}”导入ViewProfile;
导出类FakeInfo扩展组件{
建造师(道具){
超级(道具);
此.state={
用户:[
{
图片:“食物”,
姓名:“托马斯·金”,
年龄:"23岁",,
描述:“我希望结识新朋友”,
地点:“南卡罗来纳州”,
},
],
};
}
render(){
返回(
{this.state.user.map((项,键)=>)}
);
}
}
导出默认FakeInfo;

mh尝试使用:{this.state.user[0].map((项)=>(..…您得到结果了吗?得到了相同的错误mh尝试使用:{this.state.user[0].map((项)=>(..…你得到结果了吗?自从我导入FakeInfo后,我得到了相同的错误,这意味着我可以访问该文件的状态…至少这是正常React中的工作方式。我刚开始学习React native。这不应该意味着。你只是导入了某个变量中的某个文件。每个React组件都有自己的状态。阅读关于redux和global states.@samantha自从我导入FakeInfo后,这意味着我有权访问该文件的状态-这不是react或react native中的工作方式。有人或某事误导了我you@luther由于某种原因,当我使用你的解决方案时,我没有得到错误,但是文本没有呈现..因为我导入了FakeInfo,这意味着我有权访问该文件“的状态…至少它在正常的React中是这样工作的。我刚开始学习React native。这并不意味着。你只是在某个变量中导入了一些文件。每个React组件都有自己的状态。阅读关于redux和全局状态的内容。@samantha自从我导入FakeInfo后,应该意味着我有权访问该文件的状态-这不是它的工作方式。”在react或react native中的rks。某物或某人误导了you@luther由于某些原因,当我使用您的解决方案时,我没有得到错误,但文本不会呈现。。