Try alternate clear local state approach
This commit is contained in:
parent
8bad6559a6
commit
4ef6b7d591
@ -30,6 +30,7 @@ import { getNextImageUrlForRequest } from '@/services/next-image';
|
||||
import useDelay from '@/utility/useDelay';
|
||||
import usePreventNavigation from '@/utility/usePreventNavigation';
|
||||
import { useAppState } from '@/state/AppState';
|
||||
import { useRouter } from 'next/navigation';
|
||||
|
||||
const THUMBNAIL_SIZE = 300;
|
||||
|
||||
@ -65,6 +66,13 @@ export default function PhotoForm({
|
||||
|
||||
const { invalidateSwr } = useAppState();
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
const clearLocalState = useCallback(() => {
|
||||
invalidateSwr?.();
|
||||
router.refresh();
|
||||
}, [invalidateSwr, router]);
|
||||
|
||||
const changedFormKeys = useMemo(() =>
|
||||
getChangedFormFields(initialPhotoForm, formData),
|
||||
[initialPhotoForm, formData]);
|
||||
@ -374,14 +382,7 @@ export default function PhotoForm({
|
||||
<SubmitButtonWithStatus
|
||||
disabled={!canFormBeSubmitted}
|
||||
onFormStatusChange={onFormStatusChange}
|
||||
onFormSubmitToastMessage={type === 'edit'
|
||||
? formData.title
|
||||
? `"${formData.title}" updated`
|
||||
: 'Photo updated'
|
||||
: formData.title
|
||||
? `"${formData.title}" created`
|
||||
: 'Photo created'}
|
||||
onFormSubmit={invalidateSwr}
|
||||
onFormSubmit={clearLocalState}
|
||||
primary
|
||||
>
|
||||
{type === 'create' ? 'Create' : 'Update'}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user