mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-12-11 02:09:53 -06:00
Memoized initial state for editing short URL, to ensure the form values are not reset while saving
This commit is contained in:
parent
56aab349db
commit
8c7a91c7b8
@ -1,4 +1,4 @@
|
|||||||
import { FC, useEffect } from 'react';
|
import { FC, useEffect, useMemo } from 'react';
|
||||||
import { RouteComponentProps } from 'react-router';
|
import { RouteComponentProps } from 'react-router';
|
||||||
import { Button, Card } from 'reactstrap';
|
import { Button, Card } from 'reactstrap';
|
||||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||||
@ -58,6 +58,10 @@ export const EditShortUrl = (ShortUrlForm: FC<ShortUrlFormProps>) => ({
|
|||||||
const { loading, error, errorData, shortUrl } = shortUrlDetail;
|
const { loading, error, errorData, shortUrl } = shortUrlDetail;
|
||||||
const { saving, error: savingError, errorData: savingErrorData } = shortUrlEdition;
|
const { saving, error: savingError, errorData: savingErrorData } = shortUrlEdition;
|
||||||
const { domain } = parseQuery<{ domain?: string }>(search);
|
const { domain } = parseQuery<{ domain?: string }>(search);
|
||||||
|
const initialState = useMemo(
|
||||||
|
() => getInitialState(shortUrl, shortUrlCreationSettings),
|
||||||
|
[ shortUrl, shortUrlCreationSettings ],
|
||||||
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getShortUrlDetail(params.shortCode, domain);
|
getShortUrlDetail(params.shortCode, domain);
|
||||||
@ -91,7 +95,7 @@ export const EditShortUrl = (ShortUrlForm: FC<ShortUrlFormProps>) => ({
|
|||||||
</Card>
|
</Card>
|
||||||
</header>
|
</header>
|
||||||
<ShortUrlForm
|
<ShortUrlForm
|
||||||
initialState={getInitialState(shortUrl, shortUrlCreationSettings)}
|
initialState={initialState}
|
||||||
saving={saving}
|
saving={saving}
|
||||||
selectedServer={selectedServer}
|
selectedServer={selectedServer}
|
||||||
mode="edit"
|
mode="edit"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user