Eslint-plugin-react: no-setstate-from-render

Created on 1 Feb 2017  路  6Comments  路  Source: yannickcr/eslint-plugin-react

Was listening to this awesome conversation between @kentcdodds @gaearon @acdlite where they mentioned a React Fiber-induced regression where an internal application was calling setState from within render which "you are not supposed to do". The discussion is at about the ~00:38:00 mark in this video:
https://www.youtube.com/watch?v=crM1iRVGpGQ

It would be great to have this as a rule.

accepted enhancement new rule

Most helpful comment

Sounds good to me. The most simple cases should be easy, but I expect that it will be tricky to get them all. Still a partial solution is better than no solution. @matthargett want to submit a PR? You could probably copy no-did-mount-set-state.

Perhaps we should consolidate no-did-mount-set-state, no-did-update-set-state, and the proposed no-render-set-state into a single rule?

All 6 comments

Sounds good to me. The most simple cases should be easy, but I expect that it will be tricky to get them all. Still a partial solution is better than no solution. @matthargett want to submit a PR? You could probably copy no-did-mount-set-state.

Perhaps we should consolidate no-did-mount-set-state, no-did-update-set-state, and the proposed no-render-set-state into a single rule?

I was just thinking of copying no-did-update-set-state and submitting a PR, so yes. Expect one on Monday or so.

Note you'd need to be careful because if it's inside an arrow or a nested function then it's fine. That's a common pattern for event handlers.

Is this proposal accepted?
I don't mean to hijack this request, but I started a basic implementation here

you're welcome to take over @matthargett 馃槈

@adnasa pleas go for it! I thought I would knock it out that day, but other things keep getting in the way :)

hi , any update on this ? is this going to be implemented ? looks like it would definitely be useful

Was this page helpful?
0 / 5 - 0 ratings