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 useEffect by adding dependency array + remove unnecessary duration state #48

Merged
merged 3 commits into from
Aug 1, 2022

Conversation

julianbenegas
Copy link
Contributor

@julianbenegas julianbenegas commented Jul 27, 2022

An empty dependency array means calculateWidth gets called on every render. That's no good because inside calculateWidth there are two getBoundingClientRect which are expensive for the browser.

I also remove the duration state and instead derive it from the containerWidth and marqueeWidth states.

On a local test of a big site I'm building, I'm getting much less calculateWidth calls.

Should also solve #32.

@julianbenegas julianbenegas changed the title Improve useEffect by adding dependency array and removing unnecessary state Improve useEffect by adding dependency array + removing unnecessary duration state Jul 28, 2022
@julianbenegas julianbenegas changed the title Improve useEffect by adding dependency array + removing unnecessary duration state Improve useEffect by adding dependency array + remove unnecessary duration state Jul 28, 2022
@justin-chu justin-chu merged commit 2a8ea05 into justin-chu:master Aug 1, 2022
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