Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can i add Line break in JSON?

What I'm trying to do is that I want to add a line break between

remoteMessage.notification.title + remoteMessage.notification.body

title and body

If I use my code screen view show like this

enter image description here

this is my code

useEffect(() => {
  const unsubscribe = messaging().onMessage(async (remoteMessage) => {
    console.log(JSON.stringify(remoteMessage));
    Alert.alert(
      "A new FCM message arrived!",
      JSON.stringify(
        remoteMessage.notification.title + remoteMessage.notification.body
      )
    );
  });

  return unsubscribe;
}, []);

How can I fix my code? if I want to show like this?

title 
body
like image 1000
user15322469 Avatar asked Sep 05 '25 01:09

user15322469


1 Answers

You can use \n and white-space: pre-line; CSS:

const text = "Title\nBody"

function App() {
  return <div className="pre-line">{text}</div>
}

ReactDOM.render(<App />, document.getElementById('root'))
.pre-line {
  white-space: pre-line;
}
<script crossorigin src="https://unpkg.com/react@17/umd/react.production.min.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@17/umd/react-dom.production.min.js"></script>
<body>
<div id="root"></div>
</body>
like image 75
Ajeet Shah Avatar answered Sep 07 '25 09:09

Ajeet Shah