I am working on a project which is written in react-redux. I want to use the component state in component rather than global state.
My component code is:
import React from 'react';
import Input from 'src/containers/Input';
type StateType = {
searchChannel: string
};
export default class AddChannelComponent extends React.Component < void,
PropsType,
void > {
state : StateType;
constructor(props : PropsType) {
super(props);
this.state = {
searchChannel: 'test'
};
}
inputHandler(value) {
console.log("text isdddd", value);
this.setState({searchChannel: value}); <==Error Occur Here
}
render() {
return (
<div >
<p>Type your input</p>
<div>
<Input inputHandler={this.inputHandler} placeholder="Search all public channels..."/>
</div>
</div>
);
}
}
inputHandler function is invoked by the child component. Inside this this.setState({searchChannel: value}) gives me error that this.setState is not a function. Although I assign a test value to the searchChannel in constructor and it's working when I console its value in render.