useApplication
useApplication
allows access to the parent PIXI.Application
created by the <Application>
component. This hook will not work outside of an <Application>
component. Additionally, the parent application is passed via React Context. This means useApplication
will only work appropriately in child components, and in the same component that creates the <Application>
.
For example, the following example useApplication
will not be able to access the parent application:
import {
Application,
useApplication,
} from '@pixi/react';
const MyComponent = () => {
// This will cause an invariant violation.
const { app } = useApplication();
return <Application />;
};
Here's a working example where useApplication
will be able to access the parent application:
import {
Application,
useApplication,
} from '@pixi/react';
const ChildComponent = () => {
const { app } = useApplication();
return <container />;
};
const MyComponent = () => (
<Application>
<ChildComponent />
</Application>
);