How to implement service(concept in AngularJS) -like component in React

后端 未结 5 1929
忘掉有多难
忘掉有多难 2021-02-01 17:45

All:

I am pretty new to React from AngularJS. In AngularJS, there is service dependency inject which can provide a service instance to do data fetching, processing, etc

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-01 18:13

    React seems philosophically opposed to services in the Angular sense, apparently preferring tight coupling of UI and logic.

    But I have found a react-services module, which seems to offer what you are after:

    • separate your component and application state by introducing a service layer that takes care of propagating changes through your application

    • manage component dependencies in an explicit, testable way

    • there's no events and no lifecycle management - everything is done automatically for you

    • it's tiny and easy to understand - the core is less than 100 lines of code

提交回复
热议问题