---
page_source: https://juspay.io/in/docs/payment-page-enterprise/react-native/resources/react-native-code-snippets
page_title: React Native Code Snippets
---


# React Native Code Snippets




---



### **Android Hardware Back-Press Handling** 



Hyper SDK internally uses an android fragment for opening the bank page and will need the control to hardware back press when the bank page is active. This can be done by invoking **addEventListener**  on the **BackHandler**  provided by React-Native.If the blocking asynchronous call **HyperSdkReact.onBackPressed()**  returns true, Hyper SDK will handle the back press, else merchant can handle it.


#### JavaScript Code Snippet:

```javascript
componentDidMount() {
    ...
    BackHandler.addEventListener('hardwareBackPress', () => {
      return !HyperSdkReact.isNull() && HyperSdkReact.onBackPressed();
    });
    ...
  }
  componentWillUnmount() {
    ...
    BackHandler.removeEventListener('hardwareBackPress', () => null);
    ...
  }
```


**Note:** [HyperSdkReact.isNull()](https://developer.juspay.in/v4.0/docs/react-native-miscellaneous#helper-is-null) can also be called before calling **onBackPressed()**  to ensure that the HyperServices object is not null.


### **Android Permissions Handling** 



Hyper SDK needs to listen to the response of permissions asked to the user for handling auto SMS reading (wherever applicable). To do so, the merchant's activity should delegate the response to Hyper SDK once it is received from the user. This can be done by adding the following snippet in merchant's react activity (**MainActivity** ):


#### Java Code Snippet:

```java
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
     HyperSdkReactModule.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
```



### **Helper: Is Null** 



This is a helper method and can be used to check whether the HyperServices object is null at any particular moment. It is a blocking synchronous method and returns a boolean value.


#### JavaScript Code Snippet:

```javascript
var isNull: boolean = HyperSdkReact.isNull();
console.log('is HyperSDK null: ', isNull);
```



### **Is Initialised (Recommended)** 



This is a helper / optional method to check whether SDK has been initialised after [Initiate](doc:initiate #initiate). It returns a JS Promise with a boolean value.


#### JavaScript Code Snippet:

```javascript
HyperSdkReact.isInitialised().then((init: boolean) => {
    console.log('isInitialised:', init);
  });
```


