[ad_1]
I need to create a storybook for the below HOC. While creating the storybook just by simply calling withLoading it is not rendering any state. So the main thing is how can I get the props inside WihLoadingComponent
Props:
resetErrorBoundary={updateVisibleItems}
isError={error}
isLoading={loading}
loadingText={t('LOADER_TEXT')}
withLoading.js
import React from 'react';
import styles from './withLoading.module.scss';
import ErrorIcon from '@/assets/ui/home/error.svg';
/**
* @description HOC to show loaing state, error state and others
* @param {*} Component
* @returns a new component
*/
function WithLoading(Component) {
function MyFallbackComponent(props) {
const handleClick = () => {
props.resetErrorBoundary();
};
return (
<div className={styles.error}>
<div>
<ErrorIcon />
</div>
<p data-testid="errortxt">Error loading templates</p>
<button onClick={handleClick}>Retry</button>
</div>
);
}
function WihLoadingComponent({
isError,
loadingText,
isLoading,
resetErrorBoundary,
...props
}) {
if (!isLoading) return <Component {...props} />;
if (isError)
return (
<MyFallbackComponent
{...props}
resetErrorBoundary={resetErrorBoundary}
/>
);
return <div className={styles.loading} data-testid="loading">{loadingText} </div>;
}
WihLoadingComponent.isError = Component.isError;
WihLoadingComponent.loadingText = Component.loadingText;
WihLoadingComponent.isLoading = Component.isLoading;
WihLoadingComponent.resetErrorBoundary = Component.resetErrorBoundary;
return WihLoadingComponent
}
export default WithLoading;
I am using this HOC in my code like this
enter image description here
[ad_2]