I am passing data to a javascript file to build HTML based on the data type of the object. I am then exporting the module to the other javascript file to generate an HTML file with that module's HTML widget.
Below is the code I am working with. I am sure I am missing something simple, but I cannot figure out what I am doing wrong. I am also interested in advice on how to optimize what I am trying to achieve. Thanks!
function createWidget(data) {
switch(data.type) {
case "logo":
console.log(data.type);
createLogoWidget(data);
break;
case "contact":
console.log(data.type);
createContactWidget(data);
break;
case "links":
console.log(data.type);
createLinksWidget(data);
break;
default:
}
}
createLogoWidget = (data) => `
<div>createLogoWidget</div>
<div>${data.type}</div>
`;
createContactWidget = (data) => `
<div>createContactWidget</div>
<div>${data.type}</div>
`;
createLinksWidget = (data) => `
<div>createLinksWidget</div>
<div>${data.type}</div>
`;
module.exports = createWidget;