Skip to content

Instantly share code, notes, and snippets.

@mstaicu
Last active July 13, 2017 12:30
Show Gist options
  • Save mstaicu/7c0fde4541e377d24eb32ea55cb710f9 to your computer and use it in GitHub Desktop.
Save mstaicu/7c0fde4541e377d24eb32ea55cb710f9 to your computer and use it in GitHub Desktop.
Loading enhancer Higher-order Component
import React from 'react';
export default function(LoadingComponent, WrappedComponent) {
return function(props) {
return (
{
(props.status === 'LOADING') ? <LoadingComponent /> : <WrappedComponent {...props.data} />
}
)
};
};
import React from 'react';
import LoadingEnhancer from './LoadingEnhancer';
import LoadingComponent from './YourLoadingComponent';
/*
* "Spread" in an object with the following shape:
{
status: ['LOADING', 'READY', etc],
data: {} or []
}
Or pass the 'status' and 'data' props individually
depending on your data structure
*/
export default LoadingEnhancer(LoadingComponent, WrappedComponent);
function WrappedComponent() {
return (
//...
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment