-
Notifications
You must be signed in to change notification settings - Fork 395
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
Conversation
…hart.tsx Signed-off-by: Gaurav Gupta <[email protected]>
Codecov Report
@@ Coverage Diff @@
## main #1858 +/- ##
=======================================
Coverage 93.35% 93.35%
=======================================
Files 93 93
Lines 4574 4574
=======================================
Hits 4270 4270
Misses 304 304
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. |
setState
call from render function in ProbabilityDistributionChart.tsx
There was a problem hiding this 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).
The render should be called again if the 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. |
Description
Looks like we shouldn't explicitly
setState
inrender
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 likecomponentDidMount
takes care of setting the state correctly anyways.This helps in resolving the following warning trace seen in browser dev tools:-

Checklist