I need to set focus on tag in my functional component when it loads. I cannot make it work properly. Please help! Below is my code; Detail.js
import React,{useState,useEffect} from 'react';
const Detail=({course})=>{
const [myfocus]=useState(null);
useEffect(() => {
setState({
this.myfocus.focus(); //? how to set id myfocus to this.myfocus.focus()
});
return (
<div>
<h4 tabindex="0" id="myfocus">
{course.SUBJECT} {course.CATALOG_NBR}
</h4>
</div>
);
}; export default Detail;