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

turn static method of class into variable typescript

$
0
0

Hi all so currently I am making a service for my application/library i am creating and so far this is the best way I can figure out how to create a service. Ideally I would like to change this method into a variable for easier reading

import { NavigationRoute, NavigationParams } from 'react-navigation';
import { NavigationStackProp } from 'react-navigation-stack';

type Navigation =
  | NavigationStackProp<NavigationRoute<NavigationParams>, NavigationParams>
  | undefined;

export default class NavigationService {
  private static _navigator: Navigation;

  public static setNavigator(navigatorRef: Navigation) {
    this._navigator = navigatorRef;
  }

  public static navigate = (): Navigation => {
    // TODO: look into how to make this a variable
    return NavigationService._navigator;
  };
}

currently i have this

      IconPress: () => NavigationService.navigate()?.openDrawer()

but would love for it to read like this

      IconPress: () => NavigationService.navigate?.openDrawer()

Viewing all articles
Browse latest Browse all 6211

Trending Articles



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