I want to know how to use setTimeout() method. Basically, I want to click on the element after some seconds and after that perform something.
So My code is as below,
class SomeComponent extends React.PureComponent {
on_first_render = () => {
this.somemethod_called();
setTimeout(() => {
this.props.handle_click(52, 16);
},0);
setTimeout(() => {
this.props.handle_click(522, 352);
}, 0)
setTimeout(() => {
const input = document.querySelector('input[type=text]
[name=somename]');
input && input.blur();
}, 700);
As seen from above code, same handle_click() method is called in two setTimeout() methods and after 7 seconds I search for input element in the document and remove focus from it.
I feel this is clumsy and not right approach... Could someone let me know how to do it in another way which is not repeated like this.
Thanks.
document.querySelector()with React in general; why not do whateverhandle_click()does directly? Also,{52, 16}is not valid Javascript...