Skip to content

Instantly share code, notes, and snippets.

@isaac-martin
Last active May 30, 2019 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaac-martin/3284594430a660a0798f23f862d399ec to your computer and use it in GitHub Desktop.
Save isaac-martin/3284594430a660a0798f23f862d399ec to your computer and use it in GitHub Desktop.
lists from yaml > react

Have been talking about the best way to get data out of the yaml to then map in a component like the below

<ul>
  {listItems.map(item => (
    <li>
      {item}
    </li>
  ))}
</ul>

Option 1

 listItems:
  one: list item one
  two: list item two
  three: list item three
const listItems = Object.values(getCopy('listItems'))

Option 2

listItems:
  one: list item one
  two: list item two
  three: list item three
const listItems = [
	getCopy('listItems.one'),
	getCopy('listItems.two'),
	getCopy('listItems.three')
]

Option 3

  listItems: list item one, list item two, list item three
const listItems = getCopy('listItems').split(',')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment