Last active
July 13, 2017 12:30
-
-
Save mstaicu/7c0fde4541e377d24eb32ea55cb710f9 to your computer and use it in GitHub Desktop.
Loading enhancer Higher-order Component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
export default function(LoadingComponent, WrappedComponent) { | |
return function(props) { | |
return ( | |
{ | |
(props.status === 'LOADING') ? <LoadingComponent /> : <WrappedComponent {...props.data} /> | |
} | |
) | |
}; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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