Skip to content

Commit dc74629

Browse files
mohas22mohas22
authored andcommitted
trigger useeffect on value change
1 parent 3041577 commit dc74629

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

packages/react-sdk-components/src/components/field/Date/Date.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState } from 'react';
1+
import { useEffect, useState } from 'react';
22
import { DatePicker } from '@mui/x-date-pickers/DatePicker';
33
import dayjs, { Dayjs } from 'dayjs';
44

@@ -39,6 +39,10 @@ export default function Date(props: DateProps) {
3939
dateFormatInfo.dateFormatStringLC = theDateFormat.dateFormatStringLC;
4040
dateFormatInfo.dateFormatMask = theDateFormat.dateFormatMask;
4141

42+
useEffect(() => {
43+
setDateValue(dayjs(value));
44+
}, [value]);
45+
4246
if (displayMode === 'DISPLAY_ONLY') {
4347
const formattedDate = format(props.value, 'date', {
4448
format: dateFormatInfo.dateFormatString

packages/react-sdk-components/src/components/field/DateTime/DateTime.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState } from 'react';
1+
import { useEffect, useState } from 'react';
22
import { DateTimePicker } from '@mui/x-date-pickers/DateTimePicker';
33
import dayjs, { Dayjs } from 'dayjs';
44

@@ -34,6 +34,10 @@ export default function DateTime(props: DateTimeProps) {
3434
dateFormatInfo.dateFormatStringLC = theDateFormat.dateFormatStringLC;
3535
dateFormatInfo.dateFormatMask = theDateFormat.dateFormatMask;
3636

37+
useEffect(() => {
38+
setDateValue(dayjs(value));
39+
}, [value]);
40+
3741
if (displayMode === 'DISPLAY_ONLY') {
3842
const formattedDateTime = format(props.value, 'datetime', {
3943
format: `${dateFormatInfo.dateFormatString} hh:mm a`

packages/react-sdk-components/src/components/field/Decimal/Decimal.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { NumericFormat } from 'react-number-format';
22
import { TextField } from '@mui/material';
3-
import { useState } from 'react';
3+
import { useEffect, useState } from 'react';
44
import { getCurrencyCharacters, getCurrencyOptions } from '../Currency/currency-utils';
55
import handleEvent from '../../helpers/event-utils';
66
import { format } from '../../helpers/formatters';
@@ -58,6 +58,10 @@ export default function Decimal(props: DecimalProps) {
5858

5959
const theCurrencyOptions = getCurrencyOptions(currencyISOCode);
6060

61+
useEffect(() => {
62+
setValues(value.toString());
63+
}, [value]);
64+
6165
let readOnlyProp = {}; // Note: empty if NOT ReadOnly
6266

6367
if (readOnly) {

packages/react-sdk-components/src/components/field/Percentage/Percentage.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState } from 'react';
1+
import { useEffect, useState } from 'react';
22
import { NumericFormat } from 'react-number-format';
33
import { TextField } from '@mui/material';
44
import { getComponentFromMap } from '../../../bridge/helpers/sdk_component_map';
@@ -52,6 +52,10 @@ export default function Percentage(props: PercentageProps) {
5252
const theCurrencyOptions = getCurrencyOptions(currencyISOCode);
5353
const formattedValue = format(value, pConn.getComponentName()?.toLowerCase(), theCurrencyOptions);
5454

55+
useEffect(() => {
56+
setValues(value.toString());
57+
}, [value]);
58+
5559
let readOnlyProp = {}; // Note: empty if NOT ReadOnly
5660

5761
if (readOnly) {

0 commit comments

Comments
 (0)