I have component
const ComponentA: React.FC<ComponentAProps> = (props) => {
const [invalidFields, setInvalidFields] = React.useState([]);
return (
<ComponentB
invalidInputs = {inavlidFields.length !== 0}
/>
)
Does component B rerender when the state invalidFields changes?
2
Answers
Yes, it does rerender
Props of this component change so it should rerender
Yes, this will render, because when invalidFields changes it will also change the length and when the length changes useState -> calls the function setInvalidFields once this is set with newly changed field, it will re-execute the entire component and inavlidFields.length !== 0 becomes true and Component B Renders