Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • React Tutorial
  • React Exercise
  • React Basic Concepts
  • React Components
  • React Props
  • React Hooks
  • React Router
  • React Advanced
  • React Examples
  • React Interview Questions
  • React Projects
  • Next.js Tutorial
  • React Bootstrap
  • React Material UI
  • React Ant Design
  • React Desktop
  • React Rebass
  • React Blueprint
  • JavaScript
  • Web Technology
Open In App
Next Article:
Create a Markdown Editor using React Hooks and CodeMirror
Next article icon

Create a Markdown Editor with live preview using React

Last Updated : 24 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

In this article, we will be creating a Markdown Editor with a live preview using React. I have used easy-to-understand concepts like functional components and hooks, such as useState, to manage our app's data. Plus, we'll use the handy react-markdown npm package to show Markdown content in our editor.

Output Preview: Let us have a look at how the final output will look like.

ma
Markdown Editor

Prerequisites:

  • React JS
  • CSS
  • JSX
  • Functional Component in React

Approach to create Markdown Editor:

For creating the Markdown Editor with live preview using React, we'll start by setting up our development environment with Node.js and npm. Once that's done, we'll initialize a new React project and install the necessary dependencies, including the react-markdown npm package for rendering Markdown content. With our project ready to go, we'll start coding the Markdown Editor component. This component will consist of a textarea where users can input their Markdown content and a preview area where the rendered Markdown will be displayed in real-time. We'll utilize React's useState hook to manage the state of the Markdown content, ensuring that any changes made by the user are immediately reflected in the preview. Once our Markdown Editor component is complete, we'll integrate it into our main App component and add some basic styling to make it visually appealing.

Steps to Create the React App:

Step 1: Create React App

npx create-react-app markdown-editor

Step 2: Install React Markdown NPM Package

npm install react-markdown 

Project Structure:

markdown
Project Structure

The updated dependencies in package.json will look like:

"dependencies": {
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-markdown": "^9.0.1",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
}

Example: Created a MarkdownEditor.js file in the src directory to house the Markdown Editor component, and integrate it into the main App component by replacing the contents of App.js with the provided code snippet.

JavaScript
import React, { useState } from 'react' import ReactMarkdown from 'react-markdown' export default function MarkdownEditor() {     const [markdownInput, setMarkdownInput] = useState()     return (         <div className="App">             <div className="wrapper">                 <div className="head">                     MARKDOWN                 </div>                 <textarea                     autoFocus                     className="textarea"                     value={markdownInput}                     onChange={                         (e) =>                             setMarkdownInput(e.target.value)                     }                 ></textarea>             </div>             <div className="wrapper">                 <div className="head">                     PREIVEW                 </div>                 <ReactMarkdown                     children={markdownInput}                     components={{                         code: MarkComponent,                     }}                 />             </div>         </div>     ) } const MarkComponent = ({ value }) => {     return (         { value }     ) } 
JavaScript
import './App.css' import React from 'react' import MarkdownEditor from './MarkdownEditor'  function App() {     return (         <div>             <MarkdownEditor />         </div>     ) } export default App 
CSS
body {     height: 100vh;     width: 100%;     overflow: hidden; }  .App {     display: flex;     width: 100%;     height: 100vh;     align-items: center; }  .wrapper {     width: 45%;     height: 80%;     margin: 25px;     outline: none;     display: flex;     padding: 20px;     background: #eceeee;     flex-direction: column;     border: 2px solid #ccc;     overflow: hidden;     overflow-y: auto; }  .head {     width: 100%;     height: 40px;     border-bottom: 1px solid #ddd;     display: flex;     align-items: center;     font-size: 15px; }  textarea {     padding: 15px;     border: none;     outline: none !important;     width: 96%;     height: 100%;     overflow-x: hidden;     font-size: 17px;     resize: none;     background: #eceeee; }  .markdown {     padding: 15px;     border: none;     outline: none !important;     width: 96%;     height: 100%;     resize: none;     overflow-x: hidden;     background: #fff; } 

Steps to Run the App:

npm start

Output Preview: Open your browser and navigate to http://localhost:3000

ma


Next Article
Create a Markdown Editor using React Hooks and CodeMirror
author
maheshgaikwad
Improve
Article Tags :
  • Project
  • Web Technologies
  • ReactJS
  • Dev Scripter
  • ReactJS-Projects
  • Dev Scripter 2024

Similar Reads

  • Create a Markdown Editor using React Hooks and CodeMirror
    Creating a Markdown Editor with React Hooks and CodeMirror is a great way to build a simple yet powerful text editing tool. CodeMirror is a versatile text editor component that can be easily integrated into React applications. Here's a basic example of how you can create a Markdown editor using Reac
    4 min read
  • Create a Video Editor using React
    Video Editor is one of the useful apps in day-to-day life. In this article, we’ll walk you through the process of building a basic video editing app using React Native. The application enables users to upload, trim, and convert specific scenes to GIFs and then download the final edited file directly
    6 min read
  • Create a Text Editor App using React-Native
    In this article, we are going to implement a text editor app using React Native. It will contain multiple text formatting functionalities like bold, italic, underline, etc. We will implement Editor with a library called "react-native-pell-rich-editor." Preview of final output: Let us have a look at
    3 min read
  • Create Memes Generator App using React-Native
    The Me­me Generator App is a mobile­ application that allows users to effortlessly create memes. With its use­r-friendly interface, use­rs can choose from a wide collection of popular me­me templates and add their own customized text to the top and bottom. In this article, we will see how we can bui
    4 min read
  • Create a meme generator by using ReactJS
    In this tutorial, we’ll create a meme generator using ReactJS. In the meme generator, we have two text fields in which we enter the first text and last text. After writing the text when we click the Gen button, it creates a meme with an image and the text written on it. Preview Image: PrerequisiteTh
    3 min read
  • Create a News Reader app using React-Native
    Creating the News Reader application using React-Native language is an exciting project. Using this project, the users can read the news in the application itself, by filtering them according to the categories as per their interest. In this article, we will develop the complete News Reader applicati
    5 min read
  • How to create Emoji Picker in ReactJS ?
    Emojis have become an essential part of modern communication, adding a touch of emotion and fun to our messages and applications. In this article, we will explore how to create an Emoji Picker using ReactJS, allowing users to easily select and insert emojis into their text inputs or text areas. Prer
    2 min read
  • Online Markdown Editor using Django
    In this article, we will guide you through the process of creating an Online Markdown Editor using Django. This powerful tool allows users to seamlessly convert HTML code into a polished web output. By simply entering your HTML code into the input field, our Online Markdown Editor will instantly gen
    5 min read
  • How to develop a Progressive Web App using ReactJS ?
    Progressive React Applications respond very fast to user actions. They load fast and are engaging just like a mobile app. They can access Mobile device features, leverage the Operating System, and have a very high reach. It enables Installability, Background Syncing, Caching and Offline Support, and
    10 min read
  • Create Category Previews Using React And Tailwind CSS
    In modern web development creating visually appealing and functional components is essential for enhancing user experience. The goal is to showcase categories with distinct icons and a stylish green background using Tailwinds utility classes for a streamlined and responsive design. This article focu
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences