Refer to the code below:
<item
itemName={"laptop"}
itemDescription={"- XXXX \n - PPPP"} // how could I make a new line for this?
/>
\n is not working at this
Refer to the code below:
<item
itemName={"laptop"}
itemDescription={"- XXXX \n - PPPP"} // how could I make a new line for this?
/>
\n is not working at this
Share asked Aug 3, 2020 at 15:41 koko kakoko ka 1174 silver badges18 bronze badges 1- Does this answer your question? How can I insert a line break into a <Text> ponent in React Native? – gbalduzzi Commented Aug 3, 2020 at 15:43
1 Answer
Reset to default 4You can do something like this:
{text.split(“\n”).map(function(item) {
return (
{item}
<br/>
)
})}
In your particular case it would look like this:
itemDescription={<>XXXX <br /> - PPPP</>}
If your ponent takes nodes in that property, and not a string.
React doesn't use strings to create the HTMl, and HTML ignores line breaks, so you need to turn that string into JSX with line breaks, or paragraphs.