question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

break lines in JSON String

See original GitHub issue

I’m struggling to break lines within the string in my JSON language file.

This is what I already tried, which doesn’t break a new line:

line: "This is a line. \n This is another line. \n Yet another line",

line: ("This is a line."+ <br/> + "This is another line. \n Yet another line"),

line: ('This is a line. <br/> This is another line. \n Yet another line'),

I obviously try to make a new line after each sentence. This is how I call it:

<TooltipLink onClick={() => {
    this.toggleHelpTextDialog(t('test:test.line'));
}}/>

Any ideas? Thanks!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

9reactions
jamuhlcommented, Aug 25, 2017

You can’t do that in react - not without doing some dangerously insert html: https://zhenyong.github.io/react/tips/dangerously-set-inner-html.html

but what you can do:

...
render() {
  return (
    <div>
       {
         t('test:test.line').split('/n').map(line => <p>{line}</p>)
       }
    </div>
  )
}
...
5reactions
jamuhlcommented, Aug 25, 2017

alternative to above solution -> use markdown

https://github.com/acdlite/react-remarkable

Read more comments on GitHub >

github_iconTop Results From Across the Web

Are multi-line strings allowed in JSON? - Stack Overflow
JSON does not allow real line-breaks. You need to replace all the line breaks with \n . eg: "first line second line". can...
Read more >
How to use a line break in JSON? - Hardique Dasore - Medium
As we can't add <br/> tag in JSON, we need to use \n (newline) before the start of the next paragraph or bullet...
Read more >
Is there a way to add a simple line break to the Text field of a ...
You can use a <br> tag where you want the line break. You would just need to make sure wherever this code is...
Read more >
Escaping new line character in JSON to avoid data loading ...
JSON strings do not allow real newlines in its data; it can only have escaped newlines. Solution.
Read more >
How can I add \n(newline) In Json string - Python Help
If you need to have a newline inside a string inside JSON you can use the two literal characters \n which means you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found