React code doesn't work in codepen - Build a JavaScript Calculator

I just finished to write my code about ‘Calculator’ using React, then i tried to get the code to work in codepen to test it, but it doesn’t work. I saw the error ‘// [object Error]
{}’. However it doesn’t make sense for me because there is no any other message like line number. I will paste my codepen link below and codesandbox link, which is worked. I would be appreciate your helps.

my codepen

my codesandbox

Challenge: Front End Development Libraries Projects - Build a JavaScript Calculator

1 Like

Hey. If you are using chrome, you can simply inspect the page, and you will have the actual error message in the chrome console. In your case it’s “ReferenceError: useState is not defined”.

So the issue is with the importing statment:

import { useState } from "https://esm.sh/react";

You can replace it with:

const { useState } = React;

And it should be good

2 Likes

Thank you for your reply. I inserted the line you gave, then it works!
I didnt know that “react”(module) and “React”(object) are different. Thank you so much.

2 Likes

You’re welcome. I remember struggling a lot to get react to work on Codepen :sweat_smile:

2 Likes

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.