react-unity-webgl icon indicating copy to clipboard operation
react-unity-webgl copied to clipboard

react_1.useState is not a function in NextJS with Typescript

Open rama142694 opened this issue 1 year ago • 4 comments

hey! im using nextjs with typescript and im having this problem image i try to re make the project like in this another issue but it doesnt work. Here is my code image

and my folder structure image

image

Originally posted by @rama142694 in https://github.com/jeffreylanters/react-unity-webgl/discussions/488#discussioncomment-5956240

rama142694 avatar May 20 '23 16:05 rama142694

trying several times i achieve to know a little bit more of where the problem is and it has something to do with the next js new app folder for routing. With the pages folder it works correct

rama142694 avatar May 23 '23 14:05 rama142694

trying several times i achieve to know a little bit more of where the problem is and it has something to do with the next js new app folder for routing. With the pages folder it works correct

Do you have an example of how you implemented this in nextJs with pages structure

I am getting following error for the same

TypeError: (0 , react_unity_webgl__WEBPACK_IMPORTED_MODULE_2__.useUnityContext) is not a function

This error happened while generating the page. Any console logs will be displayed in the terminal window.

aditya-torinit avatar Jun 16 '23 10:06 aditya-torinit

trying several times i achieve to know a little bit more of where the problem is and it has something to do with the next js new app folder for routing. With the pages folder it works correct

Do you have an example of how you implemented this in nextJs with pages structure

I am getting following error for the same

TypeError: (0 , react_unity_webgl__WEBPACK_IMPORTED_MODULE_2__.useUnityContext) is not a function

This error happened while generating the page. Any console logs will be displayed in the terminal window.

Yes, here is the folder structure: image

and here is the implementation on the index page: image

rama142694 avatar Jun 16 '23 15:06 rama142694

Hey, I got this same issue. I believe it has to do with "By default, components inside app are React Server Components." which is a new part of NextJS 13. I was able to fix it by converting the component which included my Unity component to a client component by adding the 'use client' directive at the top of the file. https://nextjs.org/docs/getting-started/react-essentials#client-components

tylermcdonald avatar Jun 30 '23 23:06 tylermcdonald