Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance with lazy loading, useCallback, and useMemo #52

Closed
wants to merge 0 commits into from

Conversation

rendi12345678
Copy link
Contributor

@rendi12345678 rendi12345678 commented Jul 1, 2024

  • Implemented lazy loading for React components to reduce initial load time
  • Applied useCallback and useMemo hooks to prevent unnecessary re-renders

Copy link

netlify bot commented Jul 1, 2024

Deploy Preview for eletypes ready!

Name Link
🔨 Latest commit 25b5253
🔍 Latest deploy log https://app.netlify.com/sites/eletypes/deploys/668c05e538a6680008ddb2b6
😎 Deploy Preview https://deploy-preview-52--eletypes.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@rendi12345678
Copy link
Contributor Author

and optimize your svg image sir

@rendi12345678 rendi12345678 changed the title Improve performance with lazy loading, useCallback, useMemo, and mini… Improve performance with lazy loading, useCallback, and useMemo Jul 1, 2024
@MUYANGGUO
Copy link
Member

Thanks Rendi!
looks like
the sentence mode and the words card mode not working correctly.
Type box does not auto focus to the input.

Copy link
Member

@MUYANGGUO MUYANGGUO left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just couple of places using useCallback but we need to add the set state into it's dependency chain, otherwise I think they probably won't work.
observed issues:
we losing the auto focus (input), when components are lazy loading with useMemo, can we make the auto focus explicity for each input of the component we touched? another things are due to the useCallBack, I think the error/correct/ css changes are not triggered because of the dependency chain are empty. can test here https://deploy-preview-52--eletypes.netlify.app/

};
return { correct, incorrect, extra };
});
}, []);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems need to add currSentence, currInput as dependency, instead of empty.

src/App.js Outdated
@@ -174,7 +177,7 @@ function App() {

return (
<ThemeProvider theme={theme}>
<>
<Suspense fallback={null}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add a fallback component instead of having null? probably a loading indicator to handle the waiting to load status, if we want to use Suspense.

setCurrInput(e.target.value);
hiddenInputRef.current.value = e.target.value;
e.preventDefault();
};
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto, if we want to use usecallback, I think effectively we need to add the setstate in its dependency chain to make it work.

Copy link
Member

@MUYANGGUO MUYANGGUO Jul 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally think that converting handleUpdate with useCallback with this change won't improve too much performance, but let me know if you observed fast renderings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe need some reseach again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants