use functional updates when updating state, fixes issue with square being deselected when hover/unhover event are triggered (#1112)
This commit is contained in:
parent
b7d2254298
commit
4fabe482ab
1 changed files with 12 additions and 12 deletions
|
@ -35,25 +35,25 @@ export default function App() {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
const onHoverShape: TLPointerEventHandler = (e) => {
|
const onHoverShape: TLPointerEventHandler = (e) => {
|
||||||
setPageState({
|
setPageState((prevState) => ({
|
||||||
...pageState,
|
...prevState,
|
||||||
hoveredId: e.target,
|
hoveredId: e.target,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
const onUnhoverShape: TLPointerEventHandler = () => {
|
const onUnhoverShape: TLPointerEventHandler = () => {
|
||||||
setPageState({
|
setPageState((prevState) => ({
|
||||||
...pageState,
|
...prevState,
|
||||||
hoveredId: null,
|
hoveredId: null,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
const onPointShape: TLPointerEventHandler = (info) => {
|
const onPointShape: TLPointerEventHandler = (info) => {
|
||||||
setPageState({ ...pageState, selectedIds: [info.target] })
|
setPageState((prevState) => ({ ...prevState, selectedIds: [info.target] }))
|
||||||
}
|
}
|
||||||
|
|
||||||
const onPointCanvas: TLPointerEventHandler = () => {
|
const onPointCanvas: TLPointerEventHandler = () => {
|
||||||
setPageState({ ...pageState, selectedIds: [] })
|
setPageState((prevState) => ({ ...prevState, selectedIds: [] }))
|
||||||
}
|
}
|
||||||
|
|
||||||
const onDragShape: TLPointerEventHandler = (e) => {
|
const onDragShape: TLPointerEventHandler = (e) => {
|
||||||
|
@ -75,11 +75,11 @@ export default function App() {
|
||||||
|
|
||||||
const onPointerMove: TLPointerEventHandler = (info) => {
|
const onPointerMove: TLPointerEventHandler = (info) => {
|
||||||
if (info.shiftKey) {
|
if (info.shiftKey) {
|
||||||
setPageState((prev) => ({
|
setPageState((prevState) => ({
|
||||||
...pageState,
|
...prevState,
|
||||||
camera: {
|
camera: {
|
||||||
...prev.camera,
|
...prevState.camera,
|
||||||
point: Vec.add(prev.camera.point, info.delta),
|
point: Vec.add(prevState.camera.point, info.delta),
|
||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue