Paste HTML or React and run it as an app

Use the code editor to run your own React code with two files, see problems as you type, preview before saving and save a version. About fifteen minutes.

Goal: run your own code as an app, with two files, using Studio Library for what it may import. Time: about fifteen minutes. Plan: Studio. Before you start: some knowledge of HTML or React. No setup is needed.

1. Open the code view

  1. Create a note, choose App, and choose View code in the toolbar.

  2. Delete the starter text in the editor.

2. Paste a React app

Paste this into the editor:

import { useState } from 'react';
import './styles.css';

export default function App() {
  const [text, setText] = useState('');
  const words = text.trim() ? text.trim().split(/\s+/).length : 0;
  return (
    <main className="card">
      <h1>Word counter</h1>
      <textarea
        value={text}
        onChange={(event) => setText(event.target.value)}
        placeholder="Type or paste text"
      />
      <p>{words} words</p>
    </main>
  );
}

Look at the line above the editor. It says the code runs as React and why: it has a default export. If you pasted a full HTML page instead, it would say HTML.

SeeMyNotes tells you how your code will run.

You will see a problem: the file styles.css does not exist yet. The problems list shows the file, line and column.

3. Add the second file

  1. Choose New file and enter styles.css.

  2. Paste:

    .card { max-width: 480px; margin: 40px auto; font-family: Inter, sans-serif; }
    textarea { width: 100%; min-height: 160px; font-size: 16px; }

The problem disappears, and the preview next to the editor shows the word counter. Type in it: the count updates.

Two files, with a live preview.

4. Make a mistake on purpose

Delete a closing tag in App.jsx. The problems list names the file, line and column, and the preview shows the problem instead of a blank page. Put the tag back.

5. Save

Press Cmd+S (Ctrl+S on Windows and Linux). The first save creates the app with this code as its first version. Choose View the app to see the running app.

6. Use a library

Add a chart or an icon from the catalog, for example import { Heart } from 'lucide-react';. Importing something that is not in the library catalog is refused when you save, with a message that tells you which library.

Result

A two-file React app that runs at its own address, with versions you can restore.

Next steps

Related pages