Skip to content

Instantly share code, notes, and snippets.

@a-m-dev
Created July 27, 2018 07:58
Show Gist options
  • Save a-m-dev/e2a2e56e50708aa9fd0cb14021d507b7 to your computer and use it in GitHub Desktop.
Save a-m-dev/e2a2e56e50708aa9fd0cb14021d507b7 to your computer and use it in GitHub Desktop.
// 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: '&#xe802;',
query: '?type=breakfast',
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment