Mahamudul Hasan Rubel
HomeBlogCoursesAboutProjectsSkillsExperiencePhotosContact
Mahamudul Hasan Rubel

Senior Software Engineer crafting high-performance web applications and SaaS platforms.

Navigation

  • Home
  • Blog
  • Courses
  • About
  • Projects
  • Skills
  • Experience
  • Photos
  • Contact

Get in Touch

Available for senior/lead roles and consulting.

bd.mhrubel@gmail.comHire Me

© 2026 Mahamudul Hasan Rubel. All rights reserved.

Built with using Next.js 16 & Tailwind v4

Back to Blog
Lesson 13 of the Intermediate WordPress Plugins: REST API & React Admin course
WordPressJune 25, 20263 min read

Scaffolding the React Admin Dashboard for WordPress Plugins

Learn how to scaffold your React admin dashboard by registering a WordPress menu, creating a root container, and mounting your application into the DOM.

WordPressReactREST APIAdmin DashboardJavaScriptphpplugin-development

Previously in this course, we built a robust service layer in Building the Knowledge Base Service Layer to handle our API interactions. Now that our data fetching is ready, we need a place to display it. In this lesson, we are scaffolding the React admin dashboard, which involves three distinct phases: registering the WordPress admin menu, creating a React container component, and finally, mounting that component into the DOM.

The Bridge Between WordPress and React

WordPress is a server-side framework that renders HTML via PHP. React, however, is a client-side library that manages its own virtual DOM. To bring them together, we use a "Mounting Pattern."

We output an empty <div> with a unique ID from PHP. Then, we write a small JavaScript snippet that waits for the DOM to be ready, finds that <div>, and tells React to "take over" that specific node. This keeps WordPress in charge of the page structure while letting React handle the dynamic UI components.

1. Registering the Admin Menu

First, we need a persistent home for our dashboard. Open your main plugin file and register a new top-level menu page.

PHP
add_action( 'admin_menu', 'kb_register_admin_page' );

function kb_register_admin_page() {
    add_menu_page(
        'Knowledge Base Dashboard',
        'Knowledge Base',
        'manage_options',
        'knowledge-base',
        'kb_render_admin_page',
        'dashicons-book-alt'
    );
}

function kb_render_admin_page() {
    #6A9955">// This div is the "root" where React will mount
    echo '<div id="kb-admin-app"></div>';
}

2. Creating the React Container Component

In your src/ directory, create a folder named components and a file inside called App.js. This will serve as the root of your application.

JSX
import React from CE9178">'react';

const App = () => {
    return (
        <div className="kb-container">
            <h1>Knowledge Base Dashboard</h1>
            <p>React is successfully mounted!</p>
        </div>
    );
};

export default App;

3. Rendering React into the DOM

Now, we need to wire these two pieces together. Create an index.js file in your src/ directory. This is the entry point that your build process (configured in Introduction to @wordpress/scripts) will compile into a standalone file.

JAVASCRIPT
import React from CE9178">'react';
import { createRoot } from CE9178">'react-dom/client';
import App from CE9178">'./components/App';

const container = document.getElementById(CE9178">'kb-admin-app');

if (container) {
    const root = createRoot(container);
    root.render(<App />);
}

The Build Process

After creating these files, remember to run npm run build in your terminal. This command processes your JSX and creates the compiled JavaScript file in your build/ folder. Ensure you are enqueuing this file in your plugin using wp_enqueue_script, making sure to list wp-element as a dependency so that React is available in the browser.

Hands-on Exercise

  1. Update your PHP: Ensure you have added the wp_enqueue_script call to your admin_menu hook, pointing to your compiled build/index.js.
  2. Verify Mounting: Check your browser console. If you see the content of your App.js rendered on the admin page, you have successfully scaffolded your dashboard.
  3. Challenge: Add a simple state variable in App.js using useState that toggles a "Loading..." message when the component mounts.

Common Pitfalls

  • Missing wp-element dependency: If you forget to add wp-element to your script dependencies, React will be undefined, and your code will throw a silent error. Always check the network tab to see if react and react-dom are loading.
  • Duplicate IDs: Ensure the ID used in document.getElementById matches exactly what you echoed in your PHP function.
  • Script Execution Timing: If you try to render before the DOM is ready, your app will fail. Using the defer attribute or enqueuing your script in the footer ($in_footer = true) is best practice.
  • Layout Shifts: As discussed in React rendering and layout shifts: A guide to stable UIs, rendering dynamic content into the DOM can cause jumps if the container doesn't have a defined minimum height. Consider setting a min-height on your #kb-admin-app div.

Recap

We've moved from static PHP pages to a dynamic React-powered dashboard. By registering a dedicated menu, creating a root component, and mounting it into a specific DOM node, we've created the architecture needed for a modern WordPress plugin. This setup is the foundation for all the interactive features we'll build in the following lessons.

Up next: We will begin populating this dashboard with actual UI elements by working with @wordpress/components.

Previous lessonBuilding the Knowledge Base Service LayerNext lesson Working with @wordpress/components
Back to Blog

Similar Posts

WordPressReact DevelopmentJune 25, 20263 min read

Building the Knowledge Base Service Layer | WordPress REST API

Stop scattering fetch calls across your React components. Learn to build a clean service layer to centralize API logic and simplify your WordPress plugin.

Read more
WordPressJune 25, 20263 min read

Handling Asynchronous State in React for WordPress Plugins

Part of the course

Intermediate WordPress Plugins: REST API & React Admin

intermediate · Lesson 13 of 45

  1. 1

    Setting up the WordPress Development Environment

    3 min
  2. 2

    Introduction to @wordpress/scripts

    3 min
  3. 3

    Configuring ESLint and Prettier

    3 min

Master React state management for asynchronous API requests. Learn to implement loading, error, and success states to create a seamless WordPress admin UI.

Read more
WordPressJune 25, 20263 min read

Implementing CRUD in the Admin UI: WordPress REST API & React

Master CRUD operations in your WordPress admin dashboard. Learn to trigger API requests from React forms and lists to build truly interactive plugins.

Read more
4

Localizing Data for JavaScript

3 min
  • 5

    Anatomy of a REST API Endpoint

    3 min
  • 6

    Implementing REST API Permission Callbacks

    3 min
  • 7

    Handling GET Requests in REST API

    3 min
  • 8

    Validating and Sanitizing API Arguments

    4 min
  • 9

    Creating POST Endpoints for Data Submission

    3 min
  • 10

    Updating Existing API Resources

    3 min
  • 11

    Handling Asynchronous State in React

    3 min
  • 12

    Building the Knowledge Base Service Layer

    3 min
  • 13

    Scaffolding the React Admin Dashboard

    3 min
  • 14

    Working with @wordpress/components

    3 min
  • 15

    Creating a React Form for Submissions

    3 min
  • 16

    Implementing CRUD in the Admin UI

    3 min
  • 17

    Understanding WordPress Data Store Architecture

    Coming soon
  • 18

    Registering a Custom Data Store

    Coming soon
  • 19

    Writing Selectors for Data Access

    Coming soon
  • 20

    Defining Actions and Reducers

    Coming soon
  • 21

    Implementing Resolvers for Data Fetching

    Coming soon
  • 22

    Optimizing Performance with Selectors

    Coming soon
  • 23

    Handling Complex State Dependencies

    Coming soon
  • 24

    Implementing Nonce Verification

    Coming soon
  • 25

    Advanced Sanitization Techniques

    Coming soon
  • 26

    Input Validation and Error Handling

    Coming soon
  • 27

    Protecting Admin Screens

    Coming soon
  • 28

    Production Build Pipeline

    Coming soon
  • 29

    Debugging React in the WordPress Admin

    Coming soon
  • 30

    Building Search and Filter Functionality

    Coming soon
  • 31

    Internationalization in React

    Coming soon
  • 32

    Managing File Uploads via REST API

    Coming soon
  • 33

    Optimizing API Response Times

    Coming soon
  • 34

    Working with Date and Time in React

    Coming soon
  • 35

    Implementing Drag-and-Drop Sorting

    Coming soon
  • 36

    Creating Custom Hooks for API Logic

    Coming soon
  • 37

    Integrating with Gutenberg Blocks

    Coming soon
  • 38

    Handling Conflict Resolution

    Coming soon
  • 39

    Building a Modal Confirmation System

    Coming soon
  • 40

    Implementing Activity Logging

    Coming soon
  • 41

    Using Webpack Aliases

    Coming soon
  • 42

    Unit Testing API Endpoints

    Coming soon
  • 43

    Unit Testing React Components

    Coming soon
  • 44

    Handling Large Datasets with GraphQL

    Coming soon
  • 45

    Implementing Real-time Updates with Web

    Coming soon
  • View full course