T
T
thistlemr112019-06-18 01:29:12
React
thistlemr11, 2019-06-18 01:29:12

Event not working correctly?

class AddInfo extends Component{

    state={
        addText:false
    }

    render() {

        const {classes}=this.props
        const newStyles=injectSheet(styles)(AddInfo)
        const inState= this.state.addText?'true':'false'

        return (

            <div>
                <input  type="text" className={classes.positionForm} onChange={this.addEvent}/>
                {inState}
            </div>
        );
    }
    addEvent=()=>{
        this.setState({
            addText:!this.state.addText
        })
    }
}

There is a code above. Inside it there is a form in which the text is entered. There is also an onChange event, which I need in order to remember what was entered. However, I ran into a problem:
As far as I remember, the onChange event for text elements fires when focus is lost. However, in my code, it fires every time a number-letter-character is entered into my input. I don't know how to fix it.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2019-06-18
@thistlemr11

Everything works as it should. If you want the handler to be called when focus is lost - replace onChange with onBlur.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question