Last active
October 14, 2019 18:00
-
-
Save akopcz2/d3b65eaf8cbdb0f8e097fadee6ca6a6d to your computer and use it in GitHub Desktop.
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 { | |
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