nogiszd / react-ts-gamepads

Library that enables users to consume Gamepad API inside React 🎮➡️⚛️
MIT License
9 stars 2 forks source link

ReferenceError: window is not defined #1

Closed RobertDaleSmith closed 1 month ago

RobertDaleSmith commented 1 month ago

Hello! Thanks for keeping this up to date. I just implemented it within my project and despite it working great I keep getting an error in my Next.js app for window is not defined. I'm assuming its related to SSR but I have not been able to resolve this issue just yet.

I thought I could make sure the component using it has "use client"; but this still did not resolve the issue. Have you run into this before or do you think it would be best to check for window var existence within this lib?

nogiszd commented 1 month ago

Hi @RobertDaleSmith and thank you for the contribution. Indeed check for window instance should resolve server-side issues with using this library. I've merged your PR into main branch.

If you have more improvements or ideas, I'll be pleased to see the contributions to this library!

RobertDaleSmith commented 1 month ago

Awesome! Thanks for the merge.

Longterm my goal is to implement webhid and to support any USB/BT HID controller outside of Gamepad API. So maybe I can just combine Gamepad API and WebHID with robust gamepad descriptor parsing into this lib.

nogiszd commented 1 month ago

Feel free to making changes, and implement more features. Any commitment to this project would be appreciated!