Skip to content

Commit

Permalink
Reduce next.js example warnings (#324)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulgb authored Nov 5, 2024
1 parent 4c4e717 commit 3577b7a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
14 changes: 7 additions & 7 deletions examples/nextjs/src/app/(demos)/presence/Presence.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client'

import { usePresence, usePresenceSetter } from '@y-sweet/react'
import { useCallback, useState } from 'react'
import { useCallback, useRef, useState } from 'react'

type Presence = { x: number; y: number; color: string; rotation: number }

Expand Down Expand Up @@ -34,8 +34,8 @@ export function Presence() {
const [myColor, _] = useState(randomColor)
const presence = usePresence<Presence>({ includeSelf: true })
const setPresence = usePresenceSetter<Presence>()
const lastRotation = useRef(0)

let lastRotation = 0
const updatePresence = useCallback(
(e: React.MouseEvent<SVGSVGElement>) => {
let rect = e.currentTarget.getBoundingClientRect()
Expand All @@ -47,12 +47,12 @@ export function Presence() {
}

let movementRotation = Math.atan2(deltaY, deltaX) * (180 / Math.PI)
let difference = ((movementRotation - lastRotation + 180) % 360) - 180
let difference = ((movementRotation - lastRotation.current + 180) % 360) - 180
if (difference < -180) difference += 360
movementRotation = lastRotation + difference
movementRotation = lastRotation.current + difference

const rotation = 0.9 * lastRotation + 0.1 * movementRotation
lastRotation = rotation
const rotation = 0.9 * lastRotation.current + 0.1 * movementRotation
lastRotation.current = rotation

setPresence({
x: e.clientX - rect.left,
Expand All @@ -61,7 +61,7 @@ export function Presence() {
rotation,
})
},
[setPresence],
[setPresence, myColor],
)

return (
Expand Down
4 changes: 2 additions & 2 deletions examples/nextjs/src/app/(demos)/voxels/VoxelEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function MovingVoxel(props: { voxel: Voxel; name?: string }) {
if (squaredDist > 0.00001) {
destPositionRef.current = dest
}
}, [props.voxel.position])
}, [props.voxel.position, position])

return (
<mesh name={props.name} position={position} scale={1}>
Expand Down Expand Up @@ -170,7 +170,7 @@ export function VoxelEditor() {
color: color,
})
},
[setGhostPosition],
[setGhostPosition, updatePresence, color],
)

const handleClick = useCallback(
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3577b7a

Please sign in to comment.