18

You know that feeling when you're coding late at night and you get an error that you just can't parse with your tired brain, and go FUCK IT ALL, FUCK IT ALL

I'm having that feeling right about now...

Comments
  • 3
    I usually get that error when I'm using this.state = ....
    Outside the constructor
    Another possibility having two set state calls right after each other, but idoubt that's your case
    Or if setState is called in render function
  • 2
    @gitpush I have a hunch of where the problem is but I can’t debug it now, I need to sleep on the problem and come back reinvigorated tomorrow...
  • 3
    Can almost always be solved by breaking up the component into smaller, data driven parts.
  • 0
    @linuswillner best of luck and you made the right decision here, rest and tomorrow you'll be in a better situation to solve it
  • 1
    You cannot use this.state outside of the constructor. Also don't call this.setState from within the render function (setState triggers the render function so doing that from within the render function is an antipattern.

    Make a call to a function that sets state () => this.someFunc().

    I believe () => this.setState() might work too.
  • 0
    Also note that while using componentWillMount will work, that function is deprecated as of react 16.3
  • 0
    @beegC0de this. So much this. I've seen way too many monolithic components and people wonder why performance is an issue
  • 2
    @NoMaDhOoK Didn’t read your comments until now, but what do you know, it was exactly as you described - I was calling setState within render inadvertently. Coding at 2 AM is really fickle
  • 0
    @linuswillner cool. Glad you managed to fix it. And yeah doing anything at 2am is dangerous XD
  • 0
    @linuswillner yup, take my advice whenever you can sleep early and begin your day around 5, I'm most productive between 5:30am and 8am, then I become lazy af lol
Your Job Suck?
Get a Better Job
Add Comment