I just switched from coding in codepen to a local environment. I am trying to do the markdown previewer but can’t for the life of me figure out how to get access to the markdown stuff after I installed it in npm. How do I add it to and import it in my project?
It depends on which which markdown package you installed. Have you looked at their documentation? Their landing pages should include few examples.
Anyways you would do something like this
const ReactMarkdown = require('react-markdown')
const input = '# This is a header\n\nAnd this is a paragraph'
ReactDOM.render(
<ReactMarkdown source={input} />,
document.getElementById('container')
)
Did you install it locally or globally? If it’s local, and you saved it as a dependency with npm install marked --save, it should be listed in your package.json file and it should be in your node modules.
If it’s global, it’s installed on your system like npm is.
So it seems i used the install command npm install -g marked which installed it to my machine but not locally. So i tried the --save and got it to work.
Three follow up questions:
if it was saved to my machine how would I have gotten it to work without redownloading it to the project?
Why is the property called “dangerously set InnerHTML” (i realize that’s discussing why you shouldn’t set it, but how does it function?)
My element refuses to update even though I’ve passed the input of the textarea from props. It gives it the initial state but isnt updating after textarea updates. Is there a trick to that?