skip to Main Content

i am conditionally rendering these dialogs , initial value of compareData is FALSE , and the compareData value is stored in redux Store . so when i change it to TRUE i can view the Dialog1 and if i again change it to FALSE i can view the Dialog2 but Dialog2 is re-rendering all the child components inside that again . so API calls also going again and fetching the same data . i want to avoid this unwanted API calls and re-render . additional info – i am using react-class-components .

{compareData ? (<Dialog1>
                <AccountDetails/>
                  <Dialog1>):
      (<Dialog2>
       <product/>
       <items/>
       <customers/>
       </Dialog2>
    )}

2

Answers


  1. you can use useMemo() to avoid the re-renders

    Login or Signup to reply.
  2. You can use css for hide the components with display: none

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