Way to disable the getInitialState warning in ES6?
See original GitHub issueI really like the convenience of the getInitialState()
API in ES5 react, so I decided to reimplement it in a simple wrapper around React.Component
, but I get an annoying warning. Is there a way to disable this warning, since I’m doing it intentionally and providing my own functionality?
Issue Analytics
- State:
- Created 8 years ago
- Reactions:3
- Comments:8 (6 by maintainers)
Top Results From Across the Web
React, ES6 - getInitialState was defined on a plain JavaScript ...
getInitialState is not used in ES6 classes. ... Allen's answer because it generates a new function each time the render() method is called....
Read more >getinitialstate was defined on app, a plain javascript class. this ...
When an instance of this ES5 BannerComponent component class is created, the getInitialState method is triggered and gives the component two stateful properties ......
Read more >Convert React.createClass to ES6 Class - Dave Ceddia
You'll get warnings in the console if you're using it in your code – and, when React 16 comes out, createClass will be...
Read more >Binding Functions and Enable/Disable State in HTML Buttons ...
In your component's constructor, go ahead and define the isDisabled state with an initial value of false . This tells the user that...
Read more >React Without ES6
var SayHello = createReactClass({ getInitialState: function() { return {message: 'Hello!'}; }, handleClick: function() { ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think it should actually be a best practice to follow what @syranide pointed out in ES6 classes. I would vote for having this approach:
this.state = this.getInitialState()
andthis.setState(this.getInitialState())
. I believe more in the reasoning of throwing an error in ES6 when there is agetInitialState
, but this is not assigned to state in the constructor, not sure how hard this would be to catch. This would bring ES5 and ES6 react conventions more close to each other, instead of people using ES6 or upgrading to ES6 renaming all of their methods. Just my 2c.I’m aware, and that’s why I made the abstraction – it’s a lot cleaner than writing
constructor()
and callingsuper()
for that one thing (in the subclassed children).Alrighty then, thanks.