I am consistently getting:
Warning: setState(...): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op. Please check the code for the SearchInput component.
I have tried following these:
https://facebook.github.io/react/docs/two-way-binding-helpers.html#linkedstatemixin-before-and-after
https://stackoverflow.com/questions/28773839/react-form-onchange-setstate-one-step-behind
The problem is simple: when a user types into the input field capture the input via the onChange
attribute and setState
import React, { Component } from 'react';
class SearchInput extends Component {
constructor() {
super();
this.state = {
inputValue: ''
};
this.onChange = this.onChange.bind(this);
}
render() {
return (
<input
type="text"
value={this.state.inputValue}
onChange={this.onChange} />
);
}
onChange(e) {
console.log('yo');
this.setState({ inputValue: e.target.value });
}
}
export default SearchInput;
How do I mount my component so that the warning goes away and I can update user input state?
UPDATE
I recently changed my .babelrc
file to this:
{
"presets": ["latest-minimal", "stage-1", "react"],
"plugins": ["react-hot-loader/babel"]
}
following this: https://github.com/gabmontes/babel-preset-latest-minimal
But as soon as I revert back to what I had before:
{
"presets": ["es2015", "stage-1", "react"],
"plugins": ["react-hot-loader/babel"]
}
the warning went away.
Something in the latest-minimal
not jiving.