Skip to content

Instantly share code, notes, and snippets.

@richleach
Created April 16, 2020 04:13
Show Gist options
  • Save richleach/c2b9e6edc3111761a51b7a0510a07e4d to your computer and use it in GitHub Desktop.
Save richleach/c2b9e6edc3111761a51b7a0510a07e4d to your computer and use it in GitHub Desktop.
REACT: I needed an easy way to look at values in the map() loop and display a different string for each given value, creating a mapping on the fly. I replaced the values on the left with the values on the right (displayActionMap). Notice the bracket notation to display the rendered value(s).
<Table hover>
<tbody>
{grades &&
grades.map((grades) => {
const displayActionMap = {
init: 'initiated',
down: 'downgrade',
reit: 'reiterates',
up: 'upgrade',
main: 'maintains'
}
return (
<tr key={Math.floor(Math.random() * 10019)}>
<td width="15%">
{grades.firm}
</td>
<td width="35%">
{displayActionMap[grades.action]}
</td>
</tr>
);
})
}
</tbody>
</Table>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment