From f4439217610b1414b249c67e5234aa2bc85a71b6 Mon Sep 17 00:00:00 2001 From: Michael Fatemi Date: Sun, 25 Jul 2021 18:06:00 -0400 Subject: [PATCH] make it use the right placeId and canDrive when loading again --- src/components/Event/EventInterestForm.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/components/Event/EventInterestForm.tsx b/src/components/Event/EventInterestForm.tsx index db39f61..73e2c4e 100644 --- a/src/components/Event/EventInterestForm.tsx +++ b/src/components/Event/EventInterestForm.tsx @@ -1,4 +1,4 @@ -import { useCallback, useRef } from 'react'; +import { useCallback, useEffect, useRef } from 'react'; import { green, lightgrey } from '../../lib/colors'; import getPlaceDetails from '../../lib/getPlaceDetails'; import { addOrUpdateEventSignup, removeEventSignup } from '../api'; @@ -15,6 +15,15 @@ export default function EventInterestForm() { const placeIdRef = useRef(null); const canDriveRef = useRef(false); + { + const signup = event.signups[me.id]; + + useEffect(() => { + placeIdRef.current = signup?.placeId ?? null; + canDriveRef.current = signup?.canDrive ?? false; + }, [signup?.canDrive, signup?.placeId]); + } + const updateSignup = useCallback(async () => { const placeId = placeIdRef.current; const canDrive = canDriveRef.current;