The best usability is invisible but powerful.

Users stopped asking questions—because everything just made sense.

LOADING
0%
PORTFOLIO
SOFTWARE ENGINEER

Insights & Articles

Latest Articles & Blogs

Thoughts on Architecture, Design, Development, and Technology

Implement Hybrid Rich Text (TinyMCE) and Markdown Editor in Next.js

Implement Hybrid Rich Text (TinyMCE) and Markdown Editor in Next.js

# Hybrid Rich Text & Markdown Editor Implementation Guide This workflow details how to implement a hybrid editor that supports both WYSIWYG (TinyMCE) and Markdown (`@uiw/react-md-editor`) modes, including automatic conversion between formats and universal rendering on the frontend. ## 1. Install Dependencies Install the necessary packages for editors and conversion utilities. ```bash pnpm add @tinymce/tinymce-react @uiw/react-md-editor @uiw/react-markdown-preview showdown turndown react-markdown rehype-raw remark-gfm lucide-react ``` - `@tinymce/tinymce-react`: For Rich Text (HTML) editing. - `@uiw/react-md-editor`: For Markdown editing with preview. - `showdown`: Converts Markdown to HTML. - `turndown`: Converts HTML to Markdown. - `react-markdown`: Renders Markdown on the frontend. - `rehype-raw`: Allows parsing HTML tags within Markdown (essential for hybrid support). - `remark-gfm`: Adds GitHub Flavored Markdown support (tables, stikethrough, etc). - `lucide-react`: For UI icons. ## 2. Create the Hybrid Editor Component Create `components/rich-text-editor.jsx` (or `.tsx`). This component manages the state and toggles between editors. ### Key Logic: - **State**: `mode` ('markdown' | 'rich'). - **Auto-Detection**: Initialize `mode` based on content (if it starts with HTML tags like `

`, ` HTML** using `showdown`. - convert **HTML -> MD** using `turndown`. ```jsx 'use client'; import { useTheme } from 'next-themes'; import dynamic from 'next/dynamic'; import { useState, useEffect } from 'react'; import '@uiw/react-md-editor/markdown-editor.css'; import '@uiw/react-markdown-preview/markdown.css'; import * as Showdown from 'showdown'; import TurndownService from 'turndown'; import { FileCode, FileText } from 'lucide-react'; // Dynamic imports to avoid SSR issues const MDEditor = dynamic( () => import('@uiw/react-md-editor').then(mod => mod.default), { ssr: false } ); const TinyEditor = dynamic( () => import('@tinymce/tinymce-react').then(mod => mod.Editor), { ssr: false } ); // Converter Setup const markdownConverter = new Showdown.Converter({ tables: true, simplifiedAutoLink: true, strikethrough: true, tasklists: true, }); const htmlConverter = new TurndownService({ headingStyle: 'atx', codeBlockStyle: 'fenced', }); export function RichTextEditor({ value, onChange, placeholder }) { const { theme } = useTheme(); const [mounted, setMounted] = useState(false); // Auto-detect initial format const isHtml = value && /<[a-z][\s\S]*>/i.test(value); const [mode, setMode] = useState(isHtml ? 'rich' : 'markdown'); useEffect(() => { setMounted(true); }, []); const toggleMode = () => { if (mode === 'markdown') { const html = markdownConverter.makeHtml(value || ''); onChange(html); setMode('rich'); } else { const markdown = htmlConverter.turndown(value || ''); onChange(markdown); setMode('markdown'); } }; if (!mounted) return null; // Placeholder skeleton here return (

{/* Toggle Button */}
{/* Conditional Rendering */} {mode === 'markdown' ? ( ) : ( )}
); } ``` ## 3. Implement Universal Frontend Rendering The frontend display page must handle both raw Markdown and HTML string (from TinyMCE). ### approach: Use `react-markdown` with `rehype-raw`. This parses Markdown *and* passes safe HTML tags through to the browser. In your page (e.g., `app/(frontend)/writings/[slug]/page.tsx`): ```tsx import ReactMarkdown from 'react-markdown'; import remarkGfm from 'remark-gfm'; import rehypeRaw from 'rehype-raw'; // ... inside your component
{content}
``` ## 4. Styling (Tailwind Typography) Ensure `@tailwindcss/typography` is installed and configured in `app/globals.css` or `tailwind.config.js`. ```css /* app/globals.css */ @plugin '@tailwindcss/typography'; ``` Apply `prose` classes to the container wrapper to automatically style headers, lists, and blockquotes for both Markdown and HTML content. ```tsx
{writing.content || ''}
```
2025-12-254 min readFront end Tips
The Rise of Serverless: A Modern Guide to Building Applications

The Rise of Serverless: A Modern Guide to Building Applications

The Rise of Serverless: A Modern Guide to Building Applications

In the early days of the web, launching an application meant buying physical hardware, racking it in a data center, and manually installing every piece of software. Then came the "Cloud Revolution," which gave us Virtual Machines (VMs) and containers—allowing us to rent hardware.

Today, we are in the midst of the next major shift: Serverless Architecture.

Despite the name, "serverless" doesn't mean servers don't exist. It means you, the developer, no longer have to care about them. In this guide, we’ll explore what serverless computing is, how it works, and why it might be the best (or worst) choice for your next project.


What Exactly is Serverless Architecture?

Serverless architecture is a cloud computing model where the provider (like AWS, Google Cloud, or Azure) automatically manages the provisioning, scaling, and maintenance of the infrastructure required to run code.

Think of it like ordering a pizza vs. owning a pizza parlor.

  • Traditional Infrastructure: You own the parlor. You have to buy the oven, pay the rent, and hire staff even if no one is ordering pizza that day.
  • Serverless: You just order the pizza. The provider handles the kitchen, the chef, and the oven. You only pay for the pizza you actually eat.

The Two Pillars of Serverless

  1. FaaS (Function as a Service): This is the "compute" part. You write a small block of code (a function) that performs one specific task, like "resize an image" or "process a payment."
  2. BaaS (Backend as a Service): These are the "extras" like databases (DynamoDB), authentication (Auth0), or storage (S3) that you use via APIs rather than managing them yourself.

How It Works: The Event-Driven Model

Serverless applications are event-driven. This means your code sits idle and costs $0 until something "triggers" it.

Common triggers include:

  • HTTP Requests: Someone visits your website or clicks a button.
  • File Uploads: A user uploads a profile picture to a storage bucket.
  • Database Changes: A new row is added to a table.
  • Scheduled Tasks: A "cron job" that runs every night at midnight.

When the trigger occurs, the cloud provider "spins up" a container, executes your code, and then immediately destroys the container once the task is done.


Why Should You Care? (The Benefits)

1. Zero Infrastructure Management

You never have to patch an OS, update a web server, or worry about hardware failure. This allows your team to focus 100% on business logic—the stuff that actually makes you money.

2. Infinite (and Automatic) Scalability

If your app goes viral and receives 10,000 requests in a single second, the provider will automatically spin up 10,000 instances of your function. When the traffic dies down, it scales back to zero. You don't have to configure a single "auto-scaling group."

3. Pay-per-Execution

In a traditional setup, you pay for a server 24/7, even if it’s sitting idle at 3:00 AM. In serverless, you are billed in increments of 100ms. If your code doesn't run, you don't pay.

4. Faster Time-to-Market

Because you aren't wrestling with environment configurations, you can go from "idea" to "deployed API" in minutes.


The Catch: Challenges of Serverless

It isn't all sunshine and rainbows. There are trade-offs you must consider:

  • Cold Starts: If a function hasn't been used in a while, the provider needs a moment to "warm it up." This can cause a 100ms to 2-second delay on the first request.
  • Vendor Lock-in: Moving a serverless app from AWS Lambda to Google Cloud Functions is much harder than moving a standard Docker container.
  • Debugging Complexity: Since the environment is ephemeral (it disappears after use), traditional debugging and monitoring can be more difficult.
  • Not for Long-Running Tasks: Most providers limit functions to 15 minutes. If you’re rendering a 2-hour 4K video, serverless isn't for you.

Best Use Cases for Serverless

Where does serverless truly shine?

  • Multimedia Processing: Automatically generating thumbnails when an image is uploaded.
  • IoT Data Ingestion: Processing millions of tiny data packets from smart devices.
  • Chatbots & Webhooks: Handling sporadic requests from third-party services like Slack or Stripe.
  • CI/CD Pipelines: Running automated tests or build scripts on every code commit.

Summary: Serverless vs. Traditional

Feature Traditional Cloud (VMs/Containers) Serverless (FaaS)
Management Manual (OS, Patches, Runtime) Managed by Provider
Scaling Manual or Rule-based Automatic & Instant
Cost Fixed (Pay for uptime) Variable (Pay for execution)
Control Full control over the environment Limited to the code layer

Final Thoughts

Serverless architecture isn't a "silver bullet" that replaces all servers. However, for modern, event-driven applications that need to scale rapidly while keeping costs low, it is an incredibly powerful tool. By abstracting the "plumbing" of the internet, serverless allows you to do what you do best: build great software.

2025-12-255 min readCloud
Optimizing React Performance

Optimizing React Performance

Practical techniques to improve the performance of your React applications.
2025-12-251 min readReact Design Pattern
CSS Grid vs Flexbox: When to Use What

CSS Grid vs Flexbox: When to Use What

A comprehensive guide to choosing the right layout method for your projects.
2025-12-251 min readCSS Tricks
The Art of API Design

The Art of API Design

Best practices for designing RESTful APIs that are intuitive and maintainable.
2025-12-251 min readBackend Application
Mastering TypeScript: Advanced Patterns

Mastering TypeScript: Advanced Patterns

Deep dive into advanced TypeScript patterns that will level up your development skills.
2025-12-251 min readTypescript
Building Scalable React Applications with Next.js 14

Building Scalable React Applications with Next.js 14

Learn how to leverage the latest features in Next.js 14 to build performant and scalable web applications.
2025-12-251 min readWeb Developemt

Ready to Start Your Project?

I'm currently available for freelance work and open to new opportunities. Let's discuss how I can help bring your ideas to life.