const data = ["1","2","3","4","5","6"] // example data
const unicode = • // This is the unicode that I want to put in the jsx
<div>
{
data.map((item)=>(
item + <span>unicode</span>
))
}
</div>
But doesn’t work it displays [object Object]
I Tried (•)
, {"•"}
, <span>•</span>
, <span>{"•"}</span>
but none of them worked.
Any idea how I can use it unicode elements in JSX while mapping array?
2
Answers
Try
8226
code instead of•
. I got this code from https://www.toptal.com/designers/htmlarrows/punctuation/bullet/Also, your JSX syntax is not correct.
This is an example code which works as expected.
"Unicode" and Named HTML Character Entities aren’t the same thing.
•
is a named character entity for Unicode code point U+2022. To write a unicode code point in JavaScript (for instance, in a string you’re going to use later), you can use a Unicode code unit escape (u2022
) if it fits in one unit (or a pair of them if you want to manually write a surrogate pair), or a Unicode code point escape for any Unicode code point (u{2022}
).Separately, JSX fragments aren’t strings, you can’t concatenate them with
+
. To write a series of fragments all together, you can wrap them in a<React.Fragment>___</React.Fragment>
(more commonly, the shorthand:<>___</>
).Here’s an example making
unicode
a string:Here’s an example making
unicode
a fragment around•
:Note: The Stack Snippets above use the long form of React.Fragment because the version of Babel in Stack Snippets is so old it doesn’t understand the shorthand syntax. One of many problems with Stack Snippets that SE Inc. has been ignoring for years.