How can I return component and custom code in If condition in react js?

61 Views Asked by At
import { fullPageLoadingIndicator } from '../LoadingIndicator';
if (placeOrderLoading){
      return fullPageLoadingIndicator;
}

I want to add this in the return as well

window.scrollTo({
     top: 0,
     behavior: 'smooth'
});

for example this is what I want to return window scroll as well with the loading indicator which is component.

if (placeOrderLoading){
      return {
          window.scrollTo({
            top: 0,
            behavior: 'smooth'
          });
         fullPageLoadingIndicator
      };
}
1

There are 1 best solutions below

2
On BEST ANSWER

Try putting the component in the return, and if it's a component try:

if (placeOrderLoading){
      window.scrollTo({
            top: 0,
            behavior: 'smooth'
          });
      return <fullPageLoadingIndicator />;
}