Service
Services are classes that handle your application's business and logic. Service in React3L was inspired by the term with the same name in Angular framework. See https://angular.io/tutorial/toh-pt4.
-
Single instance only
Each service should have only 1 instance object and it should be initialized right after service class declaration inside the module file. For example:
export class TestService { public static sum(a: number, b: numer): number { return a + b; } public useSum(a: number, b: numer): number { return React.memo(() => a + b, [a, b]); } } export const testService: TestService = new TestService();
-
No dependency injection
Hooks maintain their own states wherever they were called so service does not need DI mechanism.
-
Domain driven design
Each service should refer to one business domain of your app. For example: Product, Order, Customer, …