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:

Actix Web Adoption Guide: Overview, Examples, And Alternatives

Actix Web adoption guide: Overview, examples, and alternatives

Actix Web is definitely a compelling option to consider, whether you are starting a new project or considering a framework switch.

Eze Sunday
Mar 18, 2024 ⋅ 8 min read
Getting Started With NativeWind: Tailwind For React Native

Getting started with NativeWind: Tailwind for React Native

Explore the integration of Tailwind CSS with React Native through NativeWind for responsive mobile design.

Chinwike Maduabuchi
Mar 15, 2024 ⋅ 11 min read
Developing A Cross Platform Tv App With React Native

Developing a cross-platform TV app with React Native

The react-tv-space-navigation library offers a comprehensive solution for developing a cross-platform TV app with React Native.

Emmanuel Odioko
Mar 14, 2024 ⋅ 10 min read
Essential Tools For Implementing React Panel Layouts

Essential tools for implementing React panel layouts

Explore some of the best tools in the React ecosystem for creating dynamic panel layouts, including react-resizable-layout and react-resizable-panels.

David Omotayo
Mar 13, 2024 ⋅ 8 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