Skip to content

[Bug]: [ELUSOC] fix: resolve conditional react hooks and eslint warnings in dashboard layouts #146

@DebasmitaBose0

Description

@DebasmitaBose0

Problem

The client code on pages like ModerationPage, UsersPage, and NewsletterPage violates the React Rules of Hooks. Hooks such as useState, useEffect, and useMemo are declared after conditional returns or called conditionally inside components. Additionally, there are severe console lint errors due to undefined global variables (like emailjs) and unused variable definitions.

Current Behavior

React throws warnings regarding conditional hook calls or ordering inconsistencies during development. The build and lint checks report multiple errors, blocking clean local validation and build flows.

Why This Improvement Is Needed

Adhering to the Rules of Hooks guarantees that state variables and side effects are consistently initialized in the same execution order on every render cycle. Eliminating styling or import errors improves code stability, rendering correctness, and prevents future build breaking bugs in CI/CD environments.

Proposed Solution

  1. Move all user permission checks and early returns (e.g., if (!role) return <Navigate />) after all hook declarations (useState, useEffect, useMemo) in ModerationPage.jsx, UsersPage.jsx, and NewsletterPage.jsx.
  2. Declare emailjs as a global variable in Contact.jsx via ESLint inline annotations (/* global emailjs */) or configure it properly.
  3. Clean up unused styling rules, imports, or dead variables across context components.

Expected Outcome

  • The project runs clean without any console errors or react-hooks warnings.
  • Frontend builds successfully.

Additional Notes

None.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions