Skip to content

Instantly share code, notes, and snippets.

@akopcz2
Last active October 14, 2019 18:00
Show Gist options
  • Save akopcz2/d3b65eaf8cbdb0f8e097fadee6ca6a6d to your computer and use it in GitHub Desktop.
Save akopcz2/d3b65eaf8cbdb0f8e097fadee6ca6a6d to your computer and use it in GitHub Desktop.
import {
Hero,
Footer
} from '../../components';
const components = {
hero: Hero,
footer: Footer
};
function DisplayThisStuff() {
/* Ajax call to API to get data 
Which returns an array to traverse over
Which contains the module name under the property "module"
*** Here's some sample data
{
"info": [{
"visible":true
"module":"hero",
}, {
"visible": false,
"module":"benefits",
}
}
/* Dependent on the "visible" attribute, render the corresponding react component */
return (
<Fragment>
{data.info.map((info, i) => {
if (info.visible) {
return React.createElement(components[info.module]);
} else {
return;
}
})}
</Fragment>
);
}
export default DisplayThisStuff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment