1

Pendo's JavaScript:

import {withPendoRN} from 'rn-pendo-sdk'
import {useRef} from 'react';

function RootNavigator(props) {
  const navigationRef = useRef();
  return (
    <NavigationContainer 
      ref={navigationRef}
      onStateChange={()=> {
        const state = navigationRef.current.getRootState()
        props.onStateChange(state);
      }} 
      onReady ={()=>{
        const state = navigationRef.current.getRootState()
        props.onStateChange(state);
      }}>
      {MainStackScreen()}
    </NavigationContainer>
  )
};

export default withPendoRN(RootNavigator);

Pendo has above mentioned JavaScript code to integrate to React Native. Can someone please provide me some pointers as to how to convert this to TypeScript. My code is FC, with export const App: FC = () => {} structure. Particularly the props object?

James Z
  • 12,209
  • 10
  • 24
  • 44
SJaka
  • 712
  • 13
  • 40
  • Does this answer your question? [React-Native - How to convert JS to TS using functional component declaration (FC)?](https://stackoverflow.com/questions/73890738/react-native-how-to-convert-js-to-ts-using-functional-component-declaration-f) – Terry Sep 29 '22 at 12:29
  • You have asked an exact copy of the same question here: https://stackoverflow.com/questions/73890738/react-native-how-to-convert-js-to-ts-using-functional-component-declaration-f – Terry Sep 29 '22 at 12:29
  • It could have been, if it had received an answer. I posted this as a subset of the larger set of questions here, hoping that targeting a subset might pique some interest. – SJaka Sep 29 '22 at 13:06

2 Answers2

1
  1. You should replace useRef with useNavigationContainerRef.
  2. You can define a vague type definition for onStateChange. This is suboptimal but since Pendo has not provided types for this yet, it is my personal preference.

So refactoring your code example:

import { NavigationContainer, useNavigationContainerRef } from '@react-navigation/native';
import { withPendoRN } from 'rn-pendo-sdk';

function RootNavigator(props: { onStateChange: (state: unknown) => unknown }) {
  const navigationRef = useNavigationContainerRef();
  return (
    <NavigationContainer
      ref={navigationRef}
      onStateChange={() => {
        const state = navigationRef.current.getRootState();
        props.onStateChange(state);
      }}
      onReady={() => {
        const state = navigationRef.current.getRootState();
        props.onStateChange(state);
      }}
    >
      {MainStackScreen()}
    </NavigationContainer>
  );
}

export default withPendoRN(RootNavigator);

1

Pendo implemented one line code integration Pendo React Native Integration
Sample code:

const PendoNavigationContainer = WithPendoReactNavigation(NavigationContainer);    

function MyApp() {
  return (
    <PendoNavigationContainer >
      {MainStackScreen()}
    </PendoNavigationContainer >
  )
};
export default MyApp;

You can also open an issue on GitHub for those kind of questions

Mike.R
  • 2,824
  • 2
  • 26
  • 34