Skip to content

Commit bb02bdf

Browse files
committed
Extract the array constant to avoid repeated allocations in the interval callback
1 parent e734c05 commit bb02bdf

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

packages/leva/src/components/UI/Joystick.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ type JoystickProps = { value: Vector2d | Vector3d } & Pick<Vector2dProps, 'onUpd
1212
children?: React.ReactNode
1313
}
1414

15+
const AXIS_KEYS = ['x', 'y', 'z'] as const
16+
1517
export function Joystick({ value, settings, onUpdate, children }: JoystickProps) {
1618
const timeout = useRef<number | undefined>()
1719
const outOfBoundsX = useRef(0)
@@ -60,8 +62,8 @@ export function Joystick({ value, settings, onUpdate, children }: JoystickProps)
6062

6163
return Array.isArray(v)
6264
? {
63-
[v1]: v[['x', 'y', 'z'].indexOf(v1)] + incX,
64-
[v2]: v[['x', 'y', 'z'].indexOf(v2)] + incY,
65+
[v1]: v[AXIS_KEYS.indexOf(v1)] + incX,
66+
[v2]: v[AXIS_KEYS.indexOf(v2)] + incY,
6567
}
6668
: {
6769
[v1]: v[v1] + incX,

0 commit comments

Comments
 (0)