I have a function that is called in many place of my app so I am trying to turn it into a helper method and just import where needed. I can't seem to get a response though from where I am calling it. Where is my syntax wrong, or maybe my approach is off entirely?
I saw the post on how to return from an Async AJAX request. This doesn't cover my problem. I know how to return the response. I just don't know how to do it from one file to another. That's my issue.
-- Help Function
export function enforceEmployeeAuth() {
let response;
API.get('user/employee_auth', {}, function(res) {
response = res
return response
})
}
Where it's called
componentDidMount() {
let auth = enforceEmployeeAuth();
// auth is undefined
}
Original Function
enforceEmployeeAuth() {
API.get('user/employee_auth', {}, function(res) {
this.setState({
employee_auth: res.employee_auth,
company_admin: res.company_admin
});
}.bind(this));
}