skip to Main Content

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


  1. Yes, it does rerender

    Props of this component change so it should rerender

    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search