Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including react-nl2br with all npm packages installed. Try it out:

require("react/package.json"); // react is a peer dependency. var reactNl2br = require("react-nl2br")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

react-nl2br v1.0.1

newlines like '\n', '\n\r' to <br /> for React



const nl2br = require('react-nl2br');
const result = nl2br('aaa\nbbb\nccc\nddd');
console.log(result); // aaa, ReactElement('br'), bbb, ReactElement('br'), ccc, ReactElement('br'), ddd

in jsx

const React = require('react');
const nl2br = require('react-nl2br');
var Hello = React.createClass({
  render: function() {
    return (
      <div>Hello {nl2br(}</div>


$ npm install react-nl2br -S
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free