MagicJS
mern.aiUniversityGitHub
  • Introduction to MagicJS
  • Why MagicJS?
  • Getting Started & Installation
  • Basic Guide
    • Create a new page using React
    • Navigate between pages
    • Create an API and integrate it with the frontend
    • Authenticate Users
      • Authorise based on Roles
    • Advanced State Management with useContent()
    • Perform CRUD Operations
    • Adding Realtime capabilities using socket
    • Handling file uploads and downloads
  • Advanced Guide
    • Understanding the concept of features in MagicJS
    • Using UI components & functions across multiple Magic Features
    • Advanced Routing of pages
    • Enable SSR
    • Access MongoDB
    • Styling pages using Tailwind CSS
  • Deploying
  • Update MagicJS
  • API References
    • Frontend
      • <LinkDisplay>
      • createSrc()
      • createUploader()
      • importUI()
      • loadConfig()
      • protected()
      • useParams()
      • useAxios()
      • useLogin()
      • useSocket()
      • useContent()
      • usePromise()
      • useNotification()
    • Backend
      • createBackendFunction()
      • data()
      • io()
      • ServerInstance()
      • utils
        • hash()
        • verifyHash()
        • initiateEmailVerification()
        • saveFileToUserUploads()
        • readFileFromUserUploads()
        • removeFileFromUserUploads()
        • assignRoleToUser()
        • unassignRoleFromUser()
        • findAllRolesByUser()
        • isUserInAnyRoles()
        • assignRoleToUser()
Powered by GitBook
On this page

Was this helpful?

  1. API References
  2. Frontend

useParams()

The useParams function in React lets you effortlessly get and use parameters from the current URL, acting like a magic key to unlock dynamic aspects of your application's URLs.

Previousprotected()NextuseAxios()

Last updated 1 year ago

Was this helpful?

Functionality Overview:

This utility retrieves parameters specified in your route paths, identified by values following colons (":") in route declarations. It returns an object with keys representing parameter names and values reflecting actual URL values. Streamlining dynamic content handling, it empowers you to seamlessly display diverse content, fetch data, or regulate functionalities based on the current URL.

Here's an example:

Imagine you have a route "/products/:id." In your ProductDetails component, leveraging useParams is as simple as:

import { useParams } from '@magicjs.dev/frontend';

function ProductDetails() {
    const { id } = useParams();
    const product = getProductById(id); // Fetch product based on id param

    // Render product details using the `product` object
    return (
        <div>
            <h1>Product Details for ID: {id}</h1>
            {/* ... Display product information fetched using the id ... */}
        </div>
    );
}

Click here to refer GitHub.