I am trying to use the pre tag inside of JSX.When you use the pre tag in JSX, it doesn't format at all. Why? In order to use the pre tag I need to do something like this:
const someCodeIWantToFormat = "var foo = 1" const preBlock = { __html: "<pre>" + pythonCode + "</pre>" }; return( <div dangerouslySetInnerHTML={ preBlock } />; )
Why?
To add script tag or code in head tag <head> , use react-helmet package.
What is JSX? JSX stands for JavaScript XML. JSX allows us to write HTML in React. JSX makes it easier to write and add HTML in React.
Note: In JSX, JavaScript expressions are written inside curly braces, and since JavaScript objects also use curly braces, the styling in the example above is written inside two sets of curly braces {{}} .
JSX stands for JavaScript XML. It is simply a syntax extension of JavaScript. It allows us to directly write HTML in React (within JavaScript code). It is easy to create a template using JSX in React, but it is not a simple template language instead it comes with the full power of JavaScript.
Template literals allow the use of multi-line strings which preserve leading/trailing white-space and new lines.
class SomeComponent extends React.Component { render() { return ( <pre>{` Hello , World . `}</pre> ) } }
class SomeComponent extends React.Component { render() { return ( <pre>{` Hello , World . `}</pre> ) } } ReactDOM.render( <SomeComponent />, document.getElementById('pre') )
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.3/react.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.3/react-dom.min.js"></script> <!-- The content rendered into this tag should match the content below. --> <div id="pre"></div> <pre> Hello , World . </pre>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With