11.1 C
Canberra
Thursday, July 31, 2025

javascript – Marker not rendering on first map faucet — solely seems after second faucet, zoom, or any interplay (Expo SDK 53, RN 0.79.5, react-native-maps 1.20.1)


I am encountering a wierd habits with the Marker element in react-native-maps when including markers dynamically.

After I faucet the map after including a marker to the editingMarkers state, the principalMarker (the inexperienced one representing the newest tapped level) does not seem instantly.

But when I do any interplay afterward — zoom, pan, faucet once more, open the FAB menu, and so on. — then the marker abruptly renders as anticipated.

It appears like the primary render is being ignored or delayed till a facet interplay forces a re-render.


Setup

  • Expo SDK: ~53.0.20
  • React Native: 0.79.5
  • react-native-maps: 1.20.1

Hook & Handlers

const [markersOnEdit, setMarkersOnEdit] = useState([]);
const [principalMarker, setPrincipalMarker] = useState(null);

const handleMapPress = (occasion: MapPressEvent) => {
  setPrincipalMarker({
    latitude: occasion.nativeEvent.coordinate.latitude,
    longitude: occasion.nativeEvent.coordinate.longitude,
  });
};

const addNewMarker = () => {
  if (!principalMarker) return;

  const epsilon = 0.00001;
  const alreadyExists = markersOnEdit.some(
    (m) =>
      Math.abs(m.latitude - principalMarker.latitude) < epsilon &&
      Math.abs(m.longitude - principalMarker.longitude) < epsilon
  );

  if (alreadyExists) {
    // That is for forcing rendering
    setMarkersOnEdit((prev) => [...prev]);
    setPrincipalMarker({ ...principalMarker });
    return;
  }

  const newMarker: EditablePoint = {
    id: generateId(),
    latitude: principalMarker.latitude,
    longitude: principalMarker.longitude,
  };

  setMarkersOnEdit((prev) => [...prev, newMarker]);
  setPrincipalMarker(null);
};

MapView + Marker rendering


  
  {principalMarker !== null && (
    
  )}

  {markersOnEdit.map((level) => (
    
  ))}


Anticipated

As quickly as I set principalMarker, it ought to render immediately.


Precise

It does not render till one other interplay occurs.


Tried thus far

  • Verified the state updates with console.log
  • Confirmed principalMarker has appropriate coordinates
  • Pressured re-renders with unfold ({ ...marker }) or cloning arrays
  • Tried calling setTimeout(() => setPrincipalMarker(...), 0)
  • Tried mapRef.present?.forceUpdate();

Questions

  • Is that this a bug with react-native-maps 1.20.1 or a quirk with React 19 / Expo SDK 53?
  • Is there any identified workaround to power the marker to render on first map press?
  • Anybody skilled related points or discovered a dependable repair?

Thanks upfront 🙏

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

[td_block_social_counter facebook="tagdiv" twitter="tagdivofficial" youtube="tagdiv" style="style8 td-social-boxed td-social-font-icons" tdc_css="eyJhbGwiOnsibWFyZ2luLWJvdHRvbSI6IjM4IiwiZGlzcGxheSI6IiJ9LCJwb3J0cmFpdCI6eyJtYXJnaW4tYm90dG9tIjoiMzAiLCJkaXNwbGF5IjoiIn0sInBvcnRyYWl0X21heF93aWR0aCI6MTAxOCwicG9ydHJhaXRfbWluX3dpZHRoIjo3Njh9" custom_title="Stay Connected" block_template_id="td_block_template_8" f_header_font_family="712" f_header_font_transform="uppercase" f_header_font_weight="500" f_header_font_size="17" border_color="#dd3333"]
- Advertisement -spot_img

Latest Articles