Telegram-Mini-Apps / reactjs-template

Telegram Mini Apps application template using React, tma.js, TypeScript and Vite.
https://t.me/tmajsbot/react_example
182 stars 61 forks source link

SDKProvider inside raect-router pages? #9

Closed danielytics closed 3 months ago

danielytics commented 3 months ago

The template opens each of the page using react-router, which appears to cause these components to not be wrapped by SDKProvider. Some hooks such as useUtils therefore don't work inside the pages, as they rely on being inside the SDKProvider, eg when I try to use useUtils inside IndexPage:

Error: useSDK was used outside the SDKProvider.

Is there a way to wrap the pages inside the same SDKProvider context to make this work with react-router pages?

danielytics commented 3 months ago

Nevermind, it wasn't anything the template was doing or react-router was doing!

It was actually that I was trying to use useUtils inside a pixi-react Sprite component, but these aren't rendered by react in the normal way, since they use the PIXI api to render (don't end up in the component tree in the react-dev-tools for example) and I assume that's what the actual cause was. So there's nothing that needs to be done on your end, my bad!

Thanks for the great template :smile: