Home / File/ use-locks.tsx — ui Source File

use-locks.tsx — ui Source File

Architecture documentation for use-locks.tsx, a tsx file in the ui codebase. 1 imports, 0 dependents.

File tsx DocumentationAtlas Changelog 1 imports 3 functions

Entity Profile

Dependency Diagram

graph LR
  ecaf6550_2376_5851_f8c3_97465aac7be4["use-locks.tsx"]
  1d141819_425e_b5fd_4c8e_32f7c6a42cf2["react"]
  ecaf6550_2376_5851_f8c3_97465aac7be4 --> 1d141819_425e_b5fd_4c8e_32f7c6a42cf2
  style ecaf6550_2376_5851_f8c3_97465aac7be4 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"use client"

import * as React from "react"

export type LockableParam =
  | "style"
  | "baseColor"
  | "theme"
  | "iconLibrary"
  | "font"
  | "menuAccent"
  | "menuColor"
  | "radius"

type LocksContextValue = {
  locks: Set<LockableParam>
  isLocked: (param: LockableParam) => boolean
  toggleLock: (param: LockableParam) => void
}

const LocksContext = React.createContext<LocksContextValue | null>(null)

export function LocksProvider({ children }: { children: React.ReactNode }) {
  const [locks, setLocks] = React.useState<Set<LockableParam>>(new Set())

  const isLocked = React.useCallback(
    (param: LockableParam) => locks.has(param),
    [locks]
  )

  const toggleLock = React.useCallback((param: LockableParam) => {
    setLocks((prev) => {
      const next = new Set(prev)
      if (next.has(param)) {
        next.delete(param)
      } else {
        next.add(param)
      }
      return next
    })
  }, [])

  const value = React.useMemo(
    () => ({ locks, isLocked, toggleLock }),
    [locks, isLocked, toggleLock]
  )

  return <LocksContext value={value}>{children}</LocksContext>
}

export function useLocks() {
  const context = React.useContext(LocksContext)
  if (!context) {
    throw new Error("useLocks must be used within LocksProvider")
  }
  return context
}

Subdomains

Dependencies

  • react

Frequently Asked Questions

What does use-locks.tsx do?
use-locks.tsx is a source file in the ui codebase, written in tsx. It belongs to the DocumentationAtlas domain, Changelog subdomain.
What functions are defined in use-locks.tsx?
use-locks.tsx defines 3 function(s): LocksProvider, param, useLocks.
What does use-locks.tsx depend on?
use-locks.tsx imports 1 module(s): react.
Where is use-locks.tsx in the architecture?
use-locks.tsx is located at apps/v4/app/(create)/hooks/use-locks.tsx (domain: DocumentationAtlas, subdomain: Changelog, directory: apps/v4/app/(create)/hooks).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free