Skip to content

Commit 6938181

Browse files
authored
useCallback to useEffect (#499)
`handleChangePixelRatio` is never called, so the pixelRatio state is never updated. I think this makes more sense as a `useEffect` so that the eventListener is created on mount, without needing to be called.
1 parent 85ef006 commit 6938181

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

documentation/docs/advanced-examples/dynamic-device-pixel-ratio.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
In the following example, we'll render our Unity Application using a device pixel ratio which matches the device pixel ratio of the browser. We'll create an event listener using a media matcher which will update the device pixel ratio of the Unity Application when the device pixel ratio changes.
44

55
```jsx showLineNumbers title="App.jsx"
6-
import React, { useState, useEffect, useCallback } from "react";
6+
import React, { useState, useEffect, useEffect } from "react";
77
import { Unity, useUnityContext } from "react-unity-webgl";
88

99
function App() {
@@ -19,7 +19,7 @@ function App() {
1919
window.devicePixelRatio
2020
);
2121

22-
const handleChangePixelRatio = useCallback(
22+
useEffect(
2323
function () {
2424
// A function which will update the device pixel ratio of the Unity
2525
// Application to match the device pixel ratio of the browser.

0 commit comments

Comments
 (0)