当前位置: 首页 > 知识库问答 >
问题:

React Hook“usEstate”在函数“app”中被称为,该函数既不是React函数组件,也不是自定义React Hook函数

权玉泽
2023-03-14

我试着用react钩子来解决一个简单的问题

const [personState,setPersonState] = useState({ DefinedObject });
"dependencies": {
    "react": "^16.8.6",
    "react-dom": "^16.8.6",
    "react-scripts": "3.0.0"
}
import React, {useState} from 'react'; 
import './App.css'; 
import Person from './Person/Person'; 

const app = props => { 
    const [personState, setPersonSate] = useState({ person:[ {name:'bishnu',age:'32'}, {name:'rasmi',age:'27'}, {name:'fretbox',age:'4'} ], }); 
    return (
        <div className="App"> 
            <h2>This is react</h2> 
            <Person name={personState.person[1].name} age="27"></Person>
            <Person name={personState.person[2].name} age="4"></Person> 
        </div> ); 
    };
    export default app;
import React from 'react'; 

const person = props => { 
    return( 
        <div>
            <h3>i am {props.name}</h3>
            <p>i am {props.age} years old</p>
            <p>{props.children}</p>
        </div> 
    )
};

export default person; 

共有1个答案

盖博简
2023-03-14

尝试将“应用程序”大写,如

const App = props => {...}

export default App;

在React中,组件需要大写,自定义钩子需要以use开始。

 类似资料: