My main objective is to indent the space within the text area by a particular amount once I click the Tab button.
I am using React JS and Bootstrap. I have created a bootstrap text area in the render function like so.
<textarea class="col-12 form-control-lg" id="exampleFormControlTextarea1"placeholder="Write some Lyrics" rows="50" onKeyDown={this.useTab()} value={this.state.lyrics}
onChange={e => this.setState({ lyrics : e.target.value },()=>{
this.updateSongs("Body")
})}
</textarea>
Outside my render function I am running the useTab() method.
useTab(e) {
console.log(e.keyCode); //press TAB and get the keyCode
}
I get the below error on running this code.
Unhandled Rejection (TypeError): Cannot read property 'keyCode' of undefined
I did refer to the below solution but was still unable to fix the error.
ReactJS handle tab character in textarea
Do I have to bind the function in the constructor? I'm not really sure why the event is not being captured and what I seem to be missing here.