Memoized initial state for editing short URL, to ensure the form values are not reset while saving

This commit is contained in:
Alejandro Celaya 2021-03-27 18:56:24 +01:00
parent 56aab349db
commit 8c7a91c7b8

View file

@ -1,4 +1,4 @@
import { FC, useEffect } from 'react';
import { FC, useEffect, useMemo } from 'react';
import { RouteComponentProps } from 'react-router';
import { Button, Card } from 'reactstrap';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
@ -58,6 +58,10 @@ export const EditShortUrl = (ShortUrlForm: FC<ShortUrlFormProps>) => ({
const { loading, error, errorData, shortUrl } = shortUrlDetail;
const { saving, error: savingError, errorData: savingErrorData } = shortUrlEdition;
const { domain } = parseQuery<{ domain?: string }>(search);
const initialState = useMemo(
() => getInitialState(shortUrl, shortUrlCreationSettings),
[ shortUrl, shortUrlCreationSettings ],
);
useEffect(() => {
getShortUrlDetail(params.shortCode, domain);
@ -91,7 +95,7 @@ export const EditShortUrl = (ShortUrlForm: FC<ShortUrlFormProps>) => ({
</Card>
</header>
<ShortUrlForm
initialState={getInitialState(shortUrl, shortUrlCreationSettings)}
initialState={initialState}
saving={saving}
selectedServer={selectedServer}
mode="edit"