Skip to content

no-setstate-from-render  #1059

@matthargett

Description

@matthargett

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.

Activity

lencioni

lencioni commented on Feb 1, 2017

@lencioni
Collaborator

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?

matthargett

matthargett commented on Feb 1, 2017

@matthargett
Author

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

gaearon

gaearon commented on Feb 2, 2017

@gaearon
Collaborator

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.

adnasa

adnasa commented on Feb 19, 2017

@adnasa
Contributor

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 😉

matthargett

matthargett commented on Feb 21, 2017

@matthargett
Author

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

sktguha

sktguha commented on Aug 20, 2020

@sktguha

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @ljharb@lencioni@adnasa@gaearon@matthargett

        Issue actions

          no-setstate-from-render · Issue #1059 · jsx-eslint/eslint-plugin-react