Custom Code - Page is in React Js | Community
Skip to main content
Level 2
January 10, 2018
Solved

Custom Code - Page is in React Js

  • January 10, 2018
  • 1 reply
  • 1625 views

Can you please let me know in which language custom code should be developed if page is in React js.

Harpreet

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by hariharans94469

Hi Harpreet,

   I am also working in React pages. Currently I am using Plain Javascript to implement the test variants. In Angular 1.x version we can create a functionality using Angular. The below code for extending the interceptor. But in React we does not have the way to write custom code.

  angular.module('appModule').config(function ($httpProvider, $provide) {

    $provide.factory('httpInterceptor', function ($q, $rootScope) {

        return {

            'request': function (config) {

           

$rootScope.$broadcast('httpRequest', config);

                return config || $q.when(config);

            },

            'response': function (response) {

$rootScope.$broadcast('httpResponse', response);

                return response || $q.when(response);

            },

            'requestError': function (rejection) {

                $rootScope.$broadcast('httpRequestError', rejection);

                return $q.reject(rejection);

            },

            'responseError': function (rejection) {

$rootScope.$broadcast('httpResponseError', rejection);

                return $q.reject(rejection);

            }

        };

    });

$httpProvider.interceptors.push('httpInterceptor');

});

Thanks,

Hariharan S

1 reply

hariharans94469
hariharans94469Accepted solution
Level 2
January 18, 2018

Hi Harpreet,

   I am also working in React pages. Currently I am using Plain Javascript to implement the test variants. In Angular 1.x version we can create a functionality using Angular. The below code for extending the interceptor. But in React we does not have the way to write custom code.

  angular.module('appModule').config(function ($httpProvider, $provide) {

    $provide.factory('httpInterceptor', function ($q, $rootScope) {

        return {

            'request': function (config) {

           

$rootScope.$broadcast('httpRequest', config);

                return config || $q.when(config);

            },

            'response': function (response) {

$rootScope.$broadcast('httpResponse', response);

                return response || $q.when(response);

            },

            'requestError': function (rejection) {

                $rootScope.$broadcast('httpRequestError', rejection);

                return $q.reject(rejection);

            },

            'responseError': function (rejection) {

$rootScope.$broadcast('httpResponseError', rejection);

                return $q.reject(rejection);

            }

        };

    });

$httpProvider.interceptors.push('httpInterceptor');

});

Thanks,

Hariharan S