Getting react to work in codepen

Can´t seem to get it to work here. Any ideas?

Try adding React to your project in the settings like I did here:

Note, I moved some JS code around

Thank you, but that doesn´t seem to be working either (or at least it´s not loading in my browser).

Well you don’t have an App component yet.

Not sure what you mean. I did finish the App and it runs if I start with npm start, but don´t know what else I should paste in the Codepen.

Have a look at how I did mine:

1 Like

You need to import the react, react-dom, and marked libraries. You will need to use CDNs, because the following will only work in your local environment, because the libraries exist on your local machine.

import React, { Component } from 'react';
import marked from "marked";

The above is missing react-dom. Also, your render refers to a component named App, but you do not have a component showing in your code.

1 Like

Thank you for the answer. Do I have to do that because I built my project using create-react-app?

You have to because Codepen can not access the files on your local machine.

Sorry if I´m being annoying. I just don´t understand why other Pens do work when building classes (and pasting the React code without importing anything, like Johnny´s) and mine doesn´t. I fail to see the difference.

Johnny’s is using Codepen’s external libraries module. Click on the gear by JS and you will see he added React there.

It´s finally working! Thanks everyone.