DEV Community

It's Just Nifty
It's Just Nifty

Posted on • Originally published at niftylittleme.com on

How To Use The Quill Rich Text Editor in Your Next.Js App Router Project

So, in one of my many projects, the Quill Rich Text Editor is used, so in this short article, we will be learning how to use it in our next.js project. Let’s dive in.

Unsplash Image by Pankaj Patel

Getting Started

You probably did this already, but just for the sake of helping the newcomers, you need to run npx create-next-app@latest and also, for quill, run npm i react-quill.

Note: The “i” in the “npm i react-quill” command stands for “install”.

Quill Editor In Use

Let’s now use the Quill Rich Text Editor in our next.js project.

We can start by importing the react-quill editor. Add these lines to your code:

'use client';
import React, { useState } from 'react';
import dynamic from 'next/dynamic';
import 'react-quill/dist/quill.snow.css';

const ReactQuill = dynamic(() => import("react-quill"), { ssr: false });
Enter fullscreen mode Exit fullscreen mode

Now, create and export a component for this page. Inside the component let’s declare a variable named value that uses useState:

const HomePage = () => {
  const [value, setValue] = useState('');
};

export default HomePage;
Enter fullscreen mode Exit fullscreen mode

With us still working inside the component, we should add a modules object, which is used with the Quill Editor to customize it. Customize it with:

  • Formats

  • Headers

  • Font

  • Font Size

  • Text Color

  • Background Color

  • Alignment

  • Lists

  • Code Blocks

  • Indents

  • Direction

  • Image

  • Video

  • Links

And this is how you do that:

  const modules = {
    toolbar: [
     [{ header: [1, 2, 3, 4, 5, 6, false] }],
     ["bold", "italic", "underline", "strike", "blockquote", "script", "code"],
     [{ font: [] }, { size: [] }],
     [{ color: [] }, { background: [] }],
     [{ align: ["right", "center", "justify"] }],
     [{ list: "ordered" }, { list: "bullet" }],
     ["code-block", { indent: "-1" }, { indent: "+1" }, { direction: "rtl" }, { direction: "ltr" }],
     ["link", "image", "video"],
    ],
  };
Enter fullscreen mode Exit fullscreen mode

To actually display the Text editor, we add:

  return (
    <main className="p-4">
        <ReactQuill value={value} onChange={setValue} modules={modules} placeholder="Start Typing Here..." />
    </main>
  );
Enter fullscreen mode Exit fullscreen mode

See, I told you this article will be short. We learned how to use the Quill Rich Text Editor in our next.js app router projects. If you liked this article, follow me on Medium and subscribe to my newsletter.

Happy Coding!

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more