React UseRef() can be use to store element values, store values outisde of the render or store previous variable values, example, counter...

Resource: https://www.webune.com/forums/react-ionic-auto-click-button-trigger-click-programmatically-automatically-without-human-click.html

1. Import:

import React, {useRef } from 'react';

2. Declare variable

const errorDiv = useRef();

3. Use in JSX:

<div ref={errorDiv}>this is the error i got</div>

4. Event

<Button variant="primary" onClick={()=>ErrorMessage()}>Show Modal</Button>

5. Execute

const ErrorMessage = (e) =>{
 errorDiv.current.click(); // trigger click on errorDiv
  console.log(`LINE 14 errorDiv=`, errorDiv);
}

6. Results

View Console Log

7. Resource Video:

t2ypzz6gJm0