I have a react component and I want to know how can I trigger a click event on it by clicking an image in my case. I tried with React's useRef(), but it doesn't work. Any idea how can I do this ? My code is bellow
import { SingleDatePicker } from 'react-dates'; <SingleDatePicker date={dateEnd} onDateChange={dateEnd => handleDateEnd( dateEnd )} focused={this.state.focusedEnd} onFocusChange={({ focused }) => this.setState({ focusedEnd : focused })} id="dateEndSearchBar" /> <img src={calendarIcon} onClick={//here I want to trigger the click on SingleDatePicker} />
SingleDatePicker) has theonClickevent itself?SelectDatePickerwhenimgclicked?stateto your states. So onimgclick event change the state and when the state change and your component render again, you have your new state and you can do everything you want with that.