pixijs / pixi-react

Write PIXI apps using React declarative style
https://pixijs.io/pixi-react/
MIT License
2.25k stars 173 forks source link

Bug: useApp () not working #410

Closed josegamboa closed 1 year ago

josegamboa commented 1 year ago

Current Behavior

Hi,

I am trying to use useApp () hook, but it is throwing up an exception, not sure if I am using it right, just checked the documentation below:

https://reactpixi.org/hooks#useapp

invariant.js:24 Uncaught Invariant Violation: No Context found with PIXI.Application. Make sure to wrap component with AppProvider at invariant (http://localhost:3004/static/js/bundle.js:484:15) at useApp (http://localhost:3004/static/js/bundle.js:21143:3) at MyComponent (http://localhost:3004/static/js/bundle.js:115:66) at renderWithHooks (http://localhost:3004/static/js/bundle.js:44313:22) at mountIndeterminateComponent (http://localhost:3004/static/js/bundle.js:47599:17) at beginWork (http://localhost:3004/static/js/bundle.js:48895:20) at HTMLUnknownElement.callCallback (http://localhost:3004/static/js/bundle.js:33905:18) at Object.invokeGuardedCallbackDev (http://localhost:3004/static/js/bundle.js:33949:20) at invokeGuardedCallback (http://localhost:3004/static/js/bundle.js:34006:35) at beginWork$1 (http://localhost:3004/static/js/bundle.js:53880:11) `

Expected Behavior

Use app constant to access the application

Steps to Reproduce

Execute next chunk of code: ` import { BlurFilter } from 'pixi.js'; import { Stage, Container, Sprite, Text, useApp } from '@pixi/react'; import { useMemo } from 'react';

const MyComponent = () => { const blurFilter = useMemo(() => new BlurFilter(4), []); const app = useApp ();

return (

); };

export default MyComponent;`

`

Environment

Possible Solution

No response

Additional Information

No response

AndreasWintherMoen commented 1 year ago

useApp is a hook which must be called inside an AppProvider. You can either create this yourself, or use the default one provided through the Stage component. This means you need a Stage component around MyComponent.

josegamboa commented 1 year ago

@AndreasWintherMoen , thanks a lot for helping with it.

Yep, I was missing the App provider in App.tsx:

Screenshot 2023-02-16 at 9 48 28 PM
josegamboa commented 1 year ago

Probably this is an opportunity to improve documentation.