How can I trigger a click event for a React component using his id?

Viewed 897

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}
    />
2 Answers

you could set a class for the component in state and modify it on the img's onClick

Related