简体   繁体   English

我尝试使用 map function 在 react-hooks useState 中循环我的列表数据,但我遇到了一个错误,目的未定义

[英]I tried to use map function for looping my list data in react-hooks useState but I stuck with an error, purposes is not defined

I tried to use map function for looping my list data in react-hooks useState but I stuck with an error, purposes is not defined.我尝试使用 map function 在 react-hooks useState 中循环我的列表数据,但我遇到了一个错误,目的未定义。 I want to show purposes in the dashboard but its not getting showed there.我想在仪表板中显示目的,但它没有显示在那里。

    const UserAccountDetails = props => {
      const { className, userid, user, ...rest } = props;
      const classes = useStyles();
      const [parameters, setParameters] = useState([]);
      // const [user, setUser] = useState({});
      const [open, setopen] = useState(false);
> Here I have defined the states. Its showing that purposes is not defined.
      const [state, changeState]=useState([
        purposes=[" "]
      ])
 > Here I have handled the events 
    const handleEventPurpose = event => {
        const { target } = event;
    
        changeState(state => ({
          ...state,
          eventTitle: target.value
        }));
      };
    
    return (
    <div>
    .....
    
    <Typography
                    gutterBottom
                    color="textSecondary"
                    variant="h6"
                    onChange={handleEventPurpose}
                  >

>Here I am mapping the purposes.But still getting error that purpose is not defined
                    {
                      state.list.map((purpose)=>(
                        <Typography>
                          <p>Purpose: {user.purpose}</p>
                        </Typography>
                      ))
                    }
                    
    
                  </Typography>
    </div>
    )
    
    

You cannot use state.list property as state is an array not an object.您不能使用 state.list 属性,因为 state 是数组而不是 object。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 React-Hooks:如何调用 useState 返回的 function - React-Hooks: How to call a function returned by useState 我如何正确使用 useEffect 进行异步获取调用和反应? 反应钩子/详尽的deps - How do i properly use useEffect for a async fetch call with react? react-hooks/exhaustive-deps 我无法显示我网站的页面,我尝试调试未捕获的语法错误 1: import { useState } from 'react' - I cannot display a page of my website, i tried debugging Uncaught Syntax Error 1: import { useState } from 'react' 我尝试使用 .map function 但它对我的代码不起作用 - I tried to use the .map function but it didn't work on my code React Hooks-我是否应该将“ useState”用于不变的状态? - React Hooks - Should I use 'useState' for state that is unchanging? React Hooks 和 useState 的使用 - React Hooks and the use of useState 我收到错误消息:```TypeError: Object(...) is not a function``` in my react app- 第一次尝试使用钩子 - I'm getting the error: ```TypeError: Object(…) is not a function``` in my react app- trying to use hooks for the first time @apollo/react-hooks 中的 useSubscription 方法加载卡住 - Loading stuck for `useSubscription` method in @apollo/react-hooks 使用 reactjs 钩子时,为什么会出现“TypeError: react__WEBPACK_IMPORTED_MODULE_1___default.a.useState is not a function”错误? - Why am I getting "TypeError: react__WEBPACK_IMPORTED_MODULE_1___default.a.useState is not a function" error when using reactjs hooks? 这是在使用状态挂钩时获取数据的正确方法吗? 我使用 usestate hook 但我不知道这是否是获取数据的正确方法 - is this the right way to fetch data while usine usestate hooks? i use usestate hook but i don't know if this the right way to fetch data
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM