2023-05-25
2714
#react
Madars Bišs
71543
May 25, 2023 ⋅ 9 min read

Building a React code editor and syntax highlighter from scratch

Madars Bišs Madars Bišs (aka Madza) is a technical writer. In his spare time, he loves to explore new topics and contribute to open-source web development.

Recent posts:

Vue logo over a brown background.

A guide to two-way binding in Vue

Learn how to implement one-way and two-way data binding in Vue.js, using v-model and advanced techniques like defineModel for better apps.

David Omotayo
Nov 22, 2024 ⋅ 10 min read
TypeScript logo over a pink and white background.

Drizzle vs. Prisma: Which ORM is best for your project?

Compare Prisma and Drizzle ORMs to learn their differences, strengths, and weaknesses for data access and migrations.

Temitope Oyedele
Nov 21, 2024 ⋅ 10 min read
Practical Implementation Of The Rule Of Least Power For Developers

Practical implementation of the Rule of Least Power for developers

It’s easy for devs to default to JavaScript to fix every problem. Let’s use the RoLP to find simpler alternatives with HTML and CSS.

Timonwa Akintokun
Nov 21, 2024 ⋅ 8 min read
Rust logo over black marble background.

Handling memory leaks in Rust

Learn how to manage memory leaks in Rust, avoid unsafe behavior, and use tools like weak references to ensure efficient programs.

Ukeje Goodness
Nov 20, 2024 ⋅ 4 min read
View all posts

2 Replies to "Building a React code editor and syntax highlighter from scratch"

  1. I found a few problems with the code above. First, in your App.js file, when you define the constants defaultLanguage and defaultTheme, you start each with and end with but the ending tag should be . Oddly, without that fix, I get a syntax error on the word 'const' inside the App() function. I only figured out the problem by initially commenting out the definitions of defaultLanguage and defaultTheme, which made the error go away. Secondly, in index.js you apparently need to add "import React from 'react';" at the top, else you get a "React is not defined" error.

  2. There are few errors in the code, I would like to correct those.

    The default value of theme and language doesn’t work, it’s undefined. You need to write those as
    `
    const defaultLanguage = “javascript” || Object.keys(languages).sort()[0];
    const defaultTheme = “atomOneDark” || Object.keys(themes).sort()[0];
    `

    and in the dropdown.jsx defaultlanguage is never used , modify the code like this. We have only added a if/else condition to check if dropdown component is selected for theme or language change.

    `
    export const Dropdown = ({ defaultLanguage ,defaultTheme, onChange, data }) => {
    const defaultValue = defaultTheme ? defaultTheme : defaultLanguage;
    return (

    {Object.keys(data)
    .sort()
    .map((item, index) => {
    return (

    {item}

    );
    })}

    );
    };

    `

    Thankyouh thankyouhhh so much for this amazing blog, very easy to understand and follow through. I’ll check your other blogs too. Thankyouh again, good work!

Leave a Reply