I have a service that returns an array of records in 'res'. Works great in my REACT components. I need to retrieve the same data in a function but I think my syntax is wrong as I get no data.
Here is the code for the service: ...
import axios from 'axios';
import * as myConstants from '../Services/User_API_Base_URL'
class UserService {
getUsers(){
return axios.get(myConstants.USER_API_BASE_URL + "users");
}
}
export default new UserService()
...
Here is the code in a Component that works great: ...
componentDidMount= async (event)=>{
UserService.getUsers().then((res) => {
this.setState({ users: res.data});
});
}
...
Here is the code in the Function that does not appear to get anything into 'datau' ...
const [datau, setDatau] = useState([]);
useEffect(() => {
const doFetchuser = async () => {
setDatau(UserService.getUsers())
};
doFetchuser();
}, []);
...
Any help getting this to work would be greatly appreciated. I am just starting to get familiar with Functions\Hooks, etc.
Rob