Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# react-three-map

## 1.0.9

### Patch Changes

- Move coord store updates into effects to stop setState during render warnings (InitR3M/AxisArrow).

## 1.0.8

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wendylabsinc/react-three-map",
"version": "1.0.8",
"version": "1.0.9",
"description": "A React wrapper library for Google Maps 3D with React Three Fiber integration",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
21 changes: 11 additions & 10 deletions src/core/use-coords.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { _roots, useThree } from "@react-three/fiber";
import { useMemo } from "react";
import { useEffect } from "react";
import { Coords } from "../api/coords";

// Use the store type from @react-three/fiber's internal _roots to avoid zustand version mismatch
Expand All @@ -13,21 +13,22 @@ export function useCoords() {
export function useSetCoords({longitude, latitude, altitude}: Coords) {

const canvas = useThree(s => s.gl.domElement);
useMemo(()=>{
const store = _roots.get(canvas)!.store; // eslint-disable-line @typescript-eslint/no-non-null-assertion
const coords : Coords = { longitude, latitude, altitude };
setCoords(store, coords);
}, [longitude, latitude, altitude]) // eslint-disable-line react-hooks/exhaustive-deps
useEffect(() => {
const root = _roots.get(canvas);
if (!root) return;
const coords: Coords = { longitude, latitude, altitude };
setCoords(root.store, coords);
}, [canvas, longitude, latitude, altitude]);
}

export function useSetRootCoords(store: FiberStore, {
longitude, latitude, altitude
}: Coords) {
useMemo(()=>{
setCoords(store, {longitude, latitude, altitude});
}, [longitude, latitude, altitude]) // eslint-disable-line react-hooks/exhaustive-deps
useEffect(() => {
setCoords(store, { longitude, latitude, altitude });
}, [store, longitude, latitude, altitude]);
}

export function setCoords(store: FiberStore, coords: Coords) {
store.setState({coords} as any) // eslint-disable-line @typescript-eslint/no-explicit-any
}
}