trying to add new line when display values in react.
Can somebody tell me what am I missing?
here is my code
const qList = qs.map(
(question, idx) => (<div key={idx}>{idx>0?<hr />:<span />}{idx+1 + '. ' +
question.split('\n').map((item) => {return (item);})}</div>)
);
return (
<div style={{ width: '100%' }}>
{ qList }
</div>
);
question data:
this is line first line.\nThe second\n and this is third
expected result:
this is line first line.
The second
and this is third
What I get:
this is line first line.,The second, and this is third
reference
UPDATED ANSWER:
const qList = qs.map((question, idx) => (
<div key={idx}>
{idx>0?<hr />:<span />}
{<span>
{idx+1 + '. '}
</span>}
{
question.split('\n').map(item =>(
<span>
{item}
<br />
</span>
))
}
</div>
));
return (
<div style={{ width: '100%' }}>
{ qList }
</div>
);