I'm trying to display some code on my website. I'm using prism which is working well, however, I'm eventually going to have to store the code I'm trying to present in a mongodb database. Right now I'm having trouble figuring out how to save the code as variable codeSnippet and presenting it. How do I do this?
What it is suppose to look like
class DispalyCodeExample extends React.Component {
constructor(props) {
super(props);
this.state = {};
}
componentDidMount() {
Prism.highlightAll();
}
render() {
return (
<pre>
<code className="language-javascript">
{`
let animals = {
cow: 'moo',
mouse: 'squeak'
}
let mouse = 'cow';
let x = animals[mouse];
`}
</code>
</pre>
);
}
}
My attempt that's not working - due to my codeSnippet variable
class DispalyCodeExample extends React.Component {
constructor(props) {
super(props);
this.state = {};
}
componentDidMount() {
Prism.highlightAll();
}
render() {
const codeSnippet = {
let animals = {
cow: 'moo',
mouse: 'squeak'
}
let mouse = 'cow';
let x = animals[mouse];
};
return (
<pre>
<code className="language-javascript">
{codeSnippet}
</code>
</pre>
);
}
}