I\'m trying to use react hooks for a simple problem
const [personState,setPersonState] = useState({ DefinedObject });
with following depend
React Hook "useState" is called in function "App" which is neither a React function component or a custom React Hook function"
For the following error , capitalize the component first letter like, and also the export also.
const App = props => {
...}
export default App;
First of all, you need to uppercase the FirstLetter of your components, in your case app should be App and person should be Person.
I tried to copy your code in the hope of finding the issue. Since you did not share how you call the App component, I can only see 1 way to result this to an issue.
This is the link in CodeSandbox: Invalid hook call.
Why? Because of the code below which is wrong:
ReactDOM.render(App(), rootElement);
It should have been:
ReactDOM.render(<App />, rootElement);
For more info, you should read Rule of Hooks - React
Hope this helps!
Capitalize the app to App will surely work.
I had the same issue. turns out that Capitalizing the "A" in "App" was the issue.
Also, if you do export: export default App; make sure you export the same name "App" as well.
In the app function you have incorrectly spelled the word setpersonSate, missing the letter t, thus it should be setpersonState.
Error:
const app = props => {
const [personState, setPersonSate] = useState({....
Solution:
const app = props => {
const [personState, setPersonState] = useState({....
Components should start with capital letters. Also remember to change the first letter in the line to export!