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:

Rxjs Adoption Guide: Overview, Examples, And Alternatives

RxJS adoption guide: Overview, examples, and alternatives

Get to know RxJS features, benefits, and more to help you understand what it is, how it works, and why you should use it.

Emmanuel Odioko
Jul 26, 2024 ⋅ 13 min read
Decoupling Monoliths Into Microservices With Feature Flags

Decoupling monoliths into microservices with feature flags

Explore how to effectively break down a monolithic application into microservices using feature flags and Flagsmith.

Kayode Adeniyi
Jul 25, 2024 ⋅ 10 min read
Lots of multi-colored blue and purplish rectangles.

Animating dialog and popover elements with CSS @starting-style

Native dialog and popover elements have their own well-defined roles in modern-day frontend web development. Dialog elements are known to […]

Rahul Chhodde
Jul 24, 2024 ⋅ 10 min read
Using Llama Index To Add Personal Data To Large Language Models

Using LlamaIndex to add personal data to LLMs

LlamaIndex provides tools for ingesting, processing, and implementing complex query workflows that combine data access with LLM prompting.

Ukeje Goodness
Jul 23, 2024 ⋅ 5 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