Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource


Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


                <div id="root">




                const List = ({ todoList, updateTodo }) => {
  return (
      { => (
          <li className="py-4" key={ } data-id={ } >
            <label className={ todo.status ? 'line-through' : ''}>
              <input onChange={ updateTodo } type="checkbox" className="mr-2"  data-id={ } checked={ todo.status }/>
              { }

const App = () => {
  const [ todoList, setTodoList ] = React.useState([]);

  const addTodo = (event) => {
    const input = document.querySelector('#todoInput');
        name: input.value,
        status: false,
    input.value = '';

  const updateTodo = (event) => {
    const { id } =;

    const newTodoList = => {
      if( === Number(id)) {
        todo.status = !todo.status;
      return todo;

    setTodoList([ ...newTodoList ]);

  const remoteAllTodo = () => {

  return (
      <div className="bg-indigo-500 p-5 h-screen">
        <div className="max-w-[768px] m-auto bg-white p-5">
          <h1 className="text-center text-2xl mb-4">React ToDoList</h1>
          <div className="flex">
            <input id="todoInput" type="text" className="w-full rounded-l-lg border-l-2 border-y-2 border-indigo-300 pl-4 focus:outline-indigo-500 focus:outline-none focus:outline-offset-0" placeholder="請輸入你的代辦事項" />
            <button onClick={ addTodo } className="w-[50px] h-[50px] border-0 bg-sky-500 hover:bg-sky-600 rounded-r-lg text-white transition duration-700">+</button>

          <List  todoList={ todoList } updateTodo={ updateTodo }/>

          <div className="flex justify-between items-center">
              目前有 <span className="font-medium">{ todoList.length }</span> 個事項待完成

            <button onClick={ remoteAllTodo } type="button" className="bg-red-300 p-2 rounded-md hover:bg-red-400 transition duration-700">Clear All Todo</button>

const root = ReactDOM.createRoot(document.querySelector('#root'));
root.render(<App />);