[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 errorThis 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? |
Replies: 2 comments
|
|
|
Solved it by: |
Solved it by: