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:

Comparing Mutative Vs Immer Vs Reducers For Data Handling In React

Comparing React state tools: Mutative vs. Immer vs. reducers

Mutative processes data with better performance than both Immer and native reducers. Let’s compare these data handling options in React.

Rashedul Alam
Apr 26, 2024 ⋅ 7 min read
Radix Ui Adoption Guide Overview Examples And Alternatives

Radix UI adoption guide: Overview, examples, and alternatives

Radix UI is quickly rising in popularity and has become an excellent go-to solution for building modern design systems and websites.

Nefe Emadamerho-Atori
Apr 25, 2024 ⋅ 11 min read
Understanding The Css Revert Layer Keyword, Part Of Css Cascade Layers

Understanding the CSS revert-layer keyword

In this article, we’ll explore CSS cascade layers — and, specifically, the revert-layer keyword — to help you refine your styling strategy.

Chimezie Innocent
Apr 24, 2024 ⋅ 6 min read
Exploring Nushell, A Rust Powered, Cross Platform Shell

Exploring Nushell, a Rust-powered, cross-platform shell

Nushell is a modern, performant, extensible shell built with Rust. Explore its pros, cons, and how to install and get started with it.

Oduah Chigozie
Apr 23, 2024 ⋅ 6 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