Reputation: 722
I am coming from a AngularJs background and trying to learn ReactJs, all the component, reduces, action thing seems quick clear, but one thing for me is missing. What is the alternative for angularJs service/factory, where do I put reusable logic, for now I just put them in separate modules like example:
export default {
loggedIn: () => {
var accessToken = localStorage.getItem('access_token');
if (!accessToken)
return false;
return true;
},
getToken : () => {
let token = localStorage.getItem('access_token');
if (token !== null)
return token;
},
getBearerToken: () => {
let token = localStorage.getItem('access_token');
if (token !== null)
return 'bearer ' + token;
}
}
And then just require it in. If this is not one of the ways, then where should it be placed?
Upvotes: 0
Views: 72
Reputation: 1006
You are right! Just make a module and require it.
I usually add my http related files in a directory called 'services' or 'api'. You can also create a directory called 'helpers' ant put logic content to avoid repeat yourself.
Upvotes: 1