[question]Why does this error(Hooks can only be called inside of the body of a function component) occurs? #223
-
Reference: I have created a corresponding demo: electron-10-demo-etrpc. However, when running it, an error occurs:
The error is reported in the file const res = trpcReact.greeting.useQuery({ name: 'Electron' }); // when execute this line it report error This line of code is not written outside of a functional component. (this is because: All hooks( including custom hooks) must run as part of component render. It cannot be run as part of event handlers.) === I think it is normal for click handler to trigger subscribe event. Is there any other way to avoid this error? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
Beta Was this translation helpful? Give feedback.
-
Solved it by:
|
Beta Was this translation helpful? Give feedback.
Solved it by: