This is the input for image url
<input className="imageInput" placeholder="upload url" onChange={this.onInputChange}/>
onChange change the state of input to the target value
onInputChange = (event)=> {
this.setState({input:event.target.value});
}
and there is an update button that update imageUrl as input
<div class="update_button"onClick={this.onUpdate}>Update</div>
onUpdate = () => {
this.setState({imageUrl:''})
}
Now while clicking the update button will change the input section with image. I use ternary operator
{this.state.imageUrl ? <!--show image here --> :<!-- shows input--> }
What i need to create is an error message if there is no image while clicking update button. The problem is while the state.imageUrl is empty, it show input section instead of error message. So how to know the presence of image and display the error message ?
this.setState(state => ({ imageUrl: state.input }));
insideonUpdate
instead?