Skip to content

the useEffects that have setState in them should be cleaned  #33

@Saidfatah

Description

@Saidfatah

currently the way some things are done in the app is not following best practices when using react
for example these two useEffects in src/screens/wallet/WalletScreen.js :

  useEffect(() => {
    if (userAccount !== null && typeof userAccount.isWinner === 'boolean') {
      setShowAnnouncementModal(true);
    }
  }, [userAccount]);

so basically if we want to clean up this useEffect we can do it this :

  useEffect(() => {
    let mounted =true 
    if (userAccount !== null  &&  typeof userAccount.isWinner === 'boolean' && mounted ) {
      setShowAnnouncementModal(true);
    }

   //useEffects returns this function when its Parent component is unmounted in this case its WalletScreen 
   return ()=>{
        mounted=false 
  } 
  }, [userAccount]);

what this does is that it'll try to setShowAnnouncementModal only if the WalletScreen component is till mounted
they should be writing this way

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions