From d86b57834f5a58a09fe592010584efea9aa81484 Mon Sep 17 00:00:00 2001 From: Pedro Guerrato Date: Fri, 18 Feb 2022 17:36:19 -0300 Subject: [PATCH] Test useeffec on props 3 --- src/lib/components/inputs/basic/Input.tsx | 11 ++++++++--- src/lib/components/inputs/basic/text/Text.tsx | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/lib/components/inputs/basic/Input.tsx b/src/lib/components/inputs/basic/Input.tsx index 112324ca..d0d49c49 100644 --- a/src/lib/components/inputs/basic/Input.tsx +++ b/src/lib/components/inputs/basic/Input.tsx @@ -1,4 +1,4 @@ -import React from 'react' +import React, { useEffect, useState } from 'react' import { isEmpty } from '../../../helpers/general' import { InputProps } from './shared' import { Checkbox } from '../Checkbox' @@ -31,7 +31,6 @@ const InputVariant: React.FC = (props) => { } export const Input = (props: InputProps) => { - verifyRequiredProps(props) const theme = useTheme() const styles = { @@ -82,7 +81,13 @@ export const Input = (props: InputProps) => { } } - const inputProps: InputProps = { ...props, inputStyles: styles } + verifyRequiredProps(props) + + const [inputProps, setInputProps] = useState({ ...props, inputStyles: styles }) + + useEffect(() => { + setInputProps({ ...props, inputStyles: styles }) + }, [props]) return ( diff --git a/src/lib/components/inputs/basic/text/Text.tsx b/src/lib/components/inputs/basic/text/Text.tsx index 685ad2de..a9b3914f 100644 --- a/src/lib/components/inputs/basic/text/Text.tsx +++ b/src/lib/components/inputs/basic/text/Text.tsx @@ -21,7 +21,7 @@ export const Text = (props: InputProps) => { }, [validationResponse]) useEffect(() => { - console.log({log: 'roso', props}) + console.log({ log: 'roso', props }) setValidationResponse(props.value) }, [props])