Created
April 16, 2020 04:13
-
-
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).
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
<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