Reputation: 129
Currently I'm working in a version of React and have an array of strings and JSX.Elements. For example, the array would look like this: [<span class="name">JCrew0</span>, "edited this document"]
. I'm then trying to display the elements of the array next to each other to make a sentence. However, because each element is on its own, the wrapping applies to each element separately, causing the spans and the strings to wrap by themselves. This then causes all sorts of weird formatting. Is there any way to combine these array elements into one JSX.Element while still applying the styles from class="name"
onto the names (wrapping them in an outer div does not work)?
Upvotes: 0
Views: 127
Reputation: 331
Perhaps you need something like this (if I assume correctly this small array is just array in array and it will stand this way):
arr.unshift(<p>);
arr.append(</p>);
const elementString = arr.join('')
Upvotes: 1