Skip to content

Commit

Permalink
Save AmountInput changes on unmount
Browse files Browse the repository at this point in the history
  • Loading branch information
joel-jeremy committed Nov 8, 2023
1 parent 1c68c3f commit 8a8b1f7
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/desktop-client/src/components/util/AmountInput.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useRef, useState } from 'react';
import React, { useEffect, useRef, useState } from 'react';

import evalArithmetic from 'loot-core/src/shared/arithmetic';
import { amountToInteger } from 'loot-core/src/shared/util';
Expand Down Expand Up @@ -59,6 +59,15 @@ export function AmountInput({
}
}

// Save changes when the component unmounts.
useEffect(() => {
return () => {
if (value !== initialValue) {
fireChange(value, negative);
}
};
}, [initialValue, value, negative]);

return (
<InputWithContent
id={id}
Expand Down

0 comments on commit 8a8b1f7

Please sign in to comment.