Skip to content

Instantly share code, notes, and snippets.

@dinocarl
Created September 19, 2018 17:24
Show Gist options
  • Save dinocarl/739e4c2e908b88c0a6a40e6960f01ab3 to your computer and use it in GitHub Desktop.
Save dinocarl/739e4c2e908b88c0a6a40e6960f01ab3 to your computer and use it in GitHub Desktop.
const data = {
selected: 2,
opts: [
{id: 1, name: `A`},
{id: 2, name: `B`},
{id: 3, name: `C`},
]
};
const selected = (a, b) => R.equals(a, b) ? `selected="selected"` : ``;
const Opt = R.curry((selectedItem, props) => `
<option value="${props.id}" ${selected(selectedItem, props.id)}>
${props.name}
</option>`);
const Opts = props => R.compose(
R.join(``),
R.map(Opt(props.selected))
)(props.opts);
const selectList = props => `
<select>
${Opts(props)}
</select>`;
selectList(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment