Created
September 19, 2018 17:24
-
-
Save dinocarl/739e4c2e908b88c0a6a40e6960f01ab3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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