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

后端 未结 5 1875
忘掉有多难
忘掉有多难 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条回答
  •  情话喂你
    2021-02-01 17:53

    I prefer to create a service in another file that exposes the 'public' functions through module.exports.

    e.g.

    module.exports = {
      foo: function(){ return bar; }
    }
    

    which is then referenced by Components using

    import myService from './routetoservice/myService'
    

提交回复
热议问题