Skip to content

Commit

Permalink
fix: watch value prop change
Browse files Browse the repository at this point in the history
  • Loading branch information
mshaaban0 committed Nov 23, 2020
1 parent 11c77ee commit 22b81a1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, {
useCallback,
useEffect,
useState,
ChangeEventHandler,
FocusEventHandler,
Expand Down Expand Up @@ -76,6 +77,10 @@ export const Select = (props: SelectProps) => {
[onChange, isDisabled],
);

useEffect(() => {
setValueState(value);
}, [value]);

const widthClass = `Select--${width}`;
const classNames = cn(styles['Select'], {
[styles['Select--disabled']]: isDisabled,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, {
useEffect,
useState,
ChangeEvent,
FocusEventHandler,
Expand Down Expand Up @@ -71,6 +72,10 @@ export const SelectField = (props: SelectFieldProps) => {
}
};

useEffect(() => {
setValueState(value);
}, [value]);

const classNames = cn(styles['SelectField'], className);

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, {
useState,
useEffect,
useCallback,
RefObject,
FocusEvent,
Expand Down Expand Up @@ -108,6 +109,10 @@ export const TextInput = (props: TextInputProps) => {
[willBlurOnEsc, onKeyDown],
);

useEffect(() => {
setValueState(value);
}, [value]);

const widthClass = `TextInput--${width}`;
const classNames = cn(styles['TextInput'], className, styles[widthClass], {
[styles['TextInput--disabled']]: disabled,
Expand Down

0 comments on commit 22b81a1

Please sign in to comment.