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

Remove setState call from render function in ProbabilityDistributionChart.tsx #1858

Merged
merged 3 commits into from
Jan 7, 2023

Conversation

gaugup
Copy link
Contributor

@gaugup gaugup commented Dec 16, 2022

Description

Looks like we shouldn't explicitly setState in render function as per https://blog.logrocket.com/using-setstate-react-components/#:~:text=The%20render()%20function%20should,avoid%20using%20setState()%20here. So removing the call setState(). Looks like componentDidMount takes care of setting the state correctly anyways.

This helps in resolving the following warning trace seen in browser dev tools:-
image

Checklist

  • I have added screenshots above for all UI changes.
  • I have added e2e tests for all UI changes.
  • Documentation was updated if it was needed.

@codecov-commenter
Copy link

codecov-commenter commented Dec 16, 2022

Codecov Report

Merging #1858 (fc2b8ba) into main (d9821c4) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main    #1858   +/-   ##
=======================================
  Coverage   93.35%   93.35%           
=======================================
  Files          93       93           
  Lines        4574     4574           
=======================================
  Hits         4270     4270           
  Misses        304      304           
Flag Coverage Δ
unittests 93.35% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@gaugup gaugup changed the title Remove setState call from render function in ProbabilityDistributionChart.tsx Remove setState call from render function in ProbabilityDistributionChart.tsx Dec 16, 2022
Copy link
Contributor

@romanlutz romanlutz left a comment

Choose a reason for hiding this comment

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

This should be fine. I remember putting this there because we don't have the probability options on first render pre-setup of the context, joint dataset etc. This should still work as it rerenders as soon as the context is there. Perhaps it makes sense to combine with the other if right before, or maybe that's obsolete now? I think it was just precondition for this if (since you need the probability options for that setState call that's removed in this PR).

@gaugup
Copy link
Contributor Author

gaugup commented Dec 22, 2022

This should be fine. I remember putting this there because we don't have the probability options on first render pre-setup of the context, joint dataset etc. This should still work as it rerenders as soon as the context is there. Perhaps it makes sense to combine with the other if right before, or maybe that's obsolete now? I think it was just precondition for this if (since you need the probability options for that setState call that's removed in this PR).

The render should be called again if the componentDidMount causes a state change which it should. That should set the state probabilityOption properly.

Ideally 'this.getProbabilityOptions()' should be cached in the state in the constructor and reused. Doesn't look like it will change in the lifecycle of this component. This should simplify the code further. But as you said that it depends on jointdataset and the context to be correctly setup.

@gaugup gaugup enabled auto-merge (squash) December 22, 2022 20:23
@gaugup gaugup merged commit 22140db into main Jan 7, 2023
@gaugup gaugup deleted the gaugup/RemoveStateChangeInRender branch January 7, 2023 19:50
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.

4 participants