Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Kenneth Lum
Kenneth Lum

Posted on • Edited on

     

Using React in JSFiddle, Coderpad, or just an HTML page

Sometimes we may need to use React in Coderpad when we interview candidates or get interviewed.

There is actually a way to do that easily in Coderpad:

  1. Just change the language toHTML
  2. Choose the Packages next to that, and chooseReact

Then we can write code such as

<scriptsrc="https://unpkg.com/react@17/umd/react.development.js"crossorigin></script><scriptsrc="https://unpkg.com/react-dom@17/umd/react-dom.development.js"crossorigin></script><scriptsrc="https://unpkg.com/babel-standalone@6/babel.min.js"></script><divid="root"></div><scripttype="text/babel">functionApp(){const[count,setCount]=React.useState(0);functionhandleClick(){setCount((c)=>c+1);}return(<div>count:{count}<buttononClick={handleClick}>Click</button></div>);}ReactDOM.render(<App/>,document.getElementById("root"));</script>
Enter fullscreen modeExit fullscreen mode

Demo in Coderpad (if it can allow public access):https://app.coderpad.io/G7E9DQQT

Demo in JSFiddle:https://jsfiddle.net/d9m68rft/

Or demo in Codesandbox:https://codesandbox.io/s/brave-leaf-6dmbu?file=/index.html

One issue is that as of right now, Coderpad or JSFiddle cannot auto format our code with the JSX, and sometimes the code is a bit messy due to indentation. Codesandbox can reformat everything on File -> Save, but some companies disallow moving the code to else where and pasting in back to Coderpad, to discourage cheating, probably.

Coderpad current uses React 16.13.1 and it is good enough for React Hooks. To be able to use React Hooks, we must use React 16.8 or above.
The scripts in the above code is suggested by the React documentation itself:https://reactjs.org/docs/add-react-to-a-website.html

We can also see the different versions of React files that can be included, in:https://cdnjs.com/libraries/react

JSFiddle has a React choice, but it requires a little bit of configuartion. The best website to use React ishttps://codesandbox.io I found.

Codersandbox is a bit tricky to share with another person. One time I had to constantly save the file, and ask the other person to constantly refresh her page. I often had to ask, "do you see the updates?"

It can in fact be quite easy:

  1. On the left side of the window, click on the bottom icon, which is "Share"

Codesandbox to share

  1. And then, copy that "live" link and share with the other person:

Alt Text

It is somewhat a pity that some companies do not allow using Codesandbox because they have more control using Coderpad with replaying the interview. But I suppose one way is to be so good in it, that the interviewer is totally impressed and can vow that you said and typed everything yourself, and vow to say that you are one of the best candidates he has met so far and recommend a strong hire.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Web Front End developer. Worked at Apple, Intuit, and Facebook before
  • Location
    Silicon Valley
  • Joined

More fromKenneth Lum

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp