我是react的新手.js我正在使用state钩子,我得到了这个错误任何解决方案请

React Hook “useState”在函数“app”中调用,它既不是 React 函数组件,也不是自定义 React Hook 函数 react-hooks/rules-of-hooks


    import React, {useState} from 'react';

    import logo from './logo.svg'

    import Person from './Person/Person';

    import './App.css';



    const app = props =>{

      const [Personstat, setPersonstate]= useState({

        persons : [

          {name:"Amir", age:"25"},

          {name:"Amir Yousaf", age:"22225"},

          {name:"Amir Yousaf Maher", age:"25"}

        ]

      });

     const switchNameHandler = () =>{

        //alert('hello Listener');

        setPersonstate( {

    persons : [

            {name:"Qasin", age:"23"},

            {name:"Qasin Yousaf", age:"22"},

            {name:"Qasin Yousaf Maher", age:"215"}

          ]

        })};

      return (

        <div className="App">

          <h1>Hello  I am trying to learn js </h1>

          <Person name={Personstat.persons[0].name} 

age={Personstat.persons[0].age}/>

          <Person name={Personstat.persons[1].name} 

age={Personstat.persons[1].age}>I am try my best for learning</Person>

          <Person name={Personstat.persons[2].name} 

age={Personstat.persons[1].age}/>

          <button onClick={switchNameHandler}>Switch Name</button>

        </div>

      );

    }

    export default app;


RISEBY
浏览 58回答 1
1回答

芜湖不芜

React 组件名称必须以大写字母开头。将组件名称更改为“应用”。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript