You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+45-10
Original file line number
Diff line number
Diff line change
@@ -40,7 +40,7 @@ To add to an existing React application, just install the dependencies:
40
40
41
41
#### Install Pixi React Dependencies
42
42
```bash
43
-
npm install pixi.js@^8.2.1 @pixi/react
43
+
npm install pixi.js@^8.2.1 @pixi/react@beta
44
44
```
45
45
46
46
#### Pixie React Usage
@@ -189,7 +189,7 @@ Pixi React supports custom components via the `extend` API. For example, you can
189
189
import { extend } from'@pixi/react'
190
190
import { Viewport } from'pixi-viewport'
191
191
192
-
extend({ viewport })
192
+
extend({ Viewport })
193
193
194
194
constMyComponent= () => {
195
195
<viewport>
@@ -219,36 +219,40 @@ declare global {
219
219
220
220
#### `useApp`
221
221
222
-
`useApp` 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](https://react.dev/reference/react/useContext). This means `useApp` will only work appropriately in _child components_, and not directly in the component that contains the `<Application>` component.
222
+
**DEPRECATED.** Use `useApplication`hook instead.
223
223
224
-
For example, the following example `useApp`**will not** be able to access the parent application:
224
+
#### `useApplication`
225
+
226
+
`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](https://react.dev/reference/react/useContext). This means `useApplication` will only work appropriately in _child components_, and in the same component that creates the `<Application>`.
227
+
228
+
For example, the following example `useApplication`**will not** be able to access the parent application:
225
229
226
230
```jsx
227
231
import {
228
232
Application,
229
-
useApp,
233
+
useApplication,
230
234
} from'@pixi/react'
231
235
232
236
constParentComponent= () => {
233
237
// This will cause an invariant violation.
234
-
constapp=useApp()
238
+
const{ app} =useApplication()
235
239
236
240
return (
237
241
<Application />
238
242
)
239
243
}
240
244
```
241
245
242
-
Here's a working example where `useApp`**will** be able to access the parent application:
246
+
Here's a working example where `useApplication`**will** be able to access the parent application:
243
247
244
248
```jsx
245
249
import {
246
250
Application,
247
-
useApp,
251
+
useApplication,
248
252
} from'@pixi/react'
249
253
250
254
constChildComponent= () => {
251
-
constapp=useApp()
255
+
const{ app} =useApplication()
252
256
253
257
console.log(app)
254
258
@@ -357,7 +361,7 @@ const MyComponent = () => {
357
361
}
358
362
```
359
363
360
-
`useTick` optionally takes a boolean as a second argument. Setting this boolean to `false` will cause the callback to be disabled until the argument is set to true again.
364
+
`useTick` optionally takes an options object. This allows control of all [`ticker.add`](https://pixijs.download/release/docs/ticker.Ticker.html#add) options, as well as adding the `isEnabled` option. Setting `isEnabled`to `false` will cause the callback to be disabled until the argument is changed to true again.
361
365
362
366
```jsx
363
367
import { useState } from'react'
@@ -373,3 +377,34 @@ const MyComponent = () => {
373
377
)
374
378
}
375
379
```
380
+
381
+
> [!CAUTION]
382
+
> The callback passed to `useTick`**is not memoised**. This can cause issues where your callback is being removed and added back to the ticker on every frame if you're mutating state in a component where `useTick` is using a non-memoised function. For example, this issue would affect the component below because we are mutating the state, causing the component to re-render constantly:
0 commit comments