Render a list with JavaScript tagged templates and Ramda
Using Ramda reduce
and an accumulator function.
(The naive approach would be just to map
over the list. Sometimes it does work, but meaning of map
is to apply a transformation to each item in the list and is not really meant to output a single string item)
const presentTagsStructure = (acc, tag) => `${acc}
<dt>${tag.name}</dt>
`
const createArticle = pageObj => `
<dl>
${R.compose(
R.reduce(R.curry(presentTagsStructure), ''),
R.prop('tags')
)(pageObj)}
</dl>
`