如何在React中实现类似于service(AngularJS中的concept)的组件 [英] How to implement service(concept in AngularJS) -like component in React
本文介绍了如何在React中实现类似于service(AngularJS中的concept)的组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
全部:
我对来自AngularJS的React很陌生.在AngularJS中,有服务依赖项注入,它可以提供服务实例来执行数据获取,处理等操作,而不是UI操作.我想知道如何在React组件中做到这一点(或实现该注入)?
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., other than UI operation. I wonder how to do this(or implement that injection) in React component?
谢谢
推荐答案
我更喜欢在另一个文件中创建服务,该文件通过module.exports公开公共"功能.
I prefer to create a service in another file that exposes the 'public' functions through module.exports.
例如
module.exports = {
foo: function(){ return bar; }
}
然后由组件使用
import myService from './routetoservice/myService'
这篇关于如何在React中实现类似于service(AngularJS中的concept)的组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文