Created
July 27, 2018 07:58
-
-
Save a-m-dev/e2a2e56e50708aa9fd0cb14021d507b7 to your computer and use it in GitHub Desktop.
This file contains 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
// hi there | |
// this is a trick that blowed my mind | |
// => BY THIS => | |
// you can use icon unicode (html unicode like ) that comes from api inside JS | |
// that is gonna be parsed and placed the icon it self instead of printing some jebrish in browser | |
// #01 . here is the function | |
const decodeHtml = (html) => { | |
var txt = document.createElement("textarea"); | |
txt.innerHTML = html; | |
return txt.value; | |
} | |
// it will recive the html entitie from api | |
// #02 . here is the code that runs it | |
// it is jsx , i took it from my project | |
return( | |
<div className='food-filter'> | |
<span className='right-line'></span> | |
<ul className='filter'> | |
{ | |
foodTypeFilterApi.map(type => ( | |
<li key={type.name}> | |
<a href={type.linkTo}> | |
<i className={`i i-${type.name}`}>{decodeHtml(type.iconCode)}</i> | |
<p>{type.faTitle}</p> | |
</a> | |
</li> | |
)) | |
} | |
</ul> | |
<span className='left-line'></span> | |
</div> | |
) | |
// #03 . this is api mock file that i use | |
export default [ | |
{ | |
name: 'breakfask', | |
faTitle: 'Breakfast', | |
linkTo: '/search', | |
iconCode: '', | |
query: '?type=breakfast', | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment