2
I have an input from a web components
that to receive the value inputado, I must create a Ref
for that input and add a eventListener
, respectively:
const nameInputRef = useRef(null)
const [userName, setUserName] = useState('')
I created a useEffect
so that when the component starts, it adds a eventListener
in that ref
. So I can manage my state change web component
for my React component:
useEffect(() => {
nameInputRef.current.addEventListener(
'inputChangedValue',
({ target: { value } }) => {
fields.username.input.onChange(value)
}
)
}, [])
My question is: React is able to automatically remove this Eventlistener when the component is destroyed?