Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

How to use class service in React Native

$
0
0

I come from the Angular world where I can have a service with methods and properties. Then I can import this class in another file, inject it in the constructor and call the class's members. Now I am working on a mobile app with React Native and Expo. I am wondering if I can do the same dependency injection.

This is what I have so far:

// HttpService.tsimport....export default class HttpService{  private field = "";  public method1 = () => {}  public method2 = () => {}  private otherMethod = () => {}}

Usage from Component:

// MakeApiCall.tsximport HttpService from "./services/HttpService";export...// HttpService.method1 is not available.

I don't want to new up an instance of HttpService every time I call the class's members.


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>