PHP 8.2.30
Preview: use-current-admin.ts Size: 1.52 KB
/proc/thread-self/root/home/byroehnu/.trash/node_modules11/adminjs/src/frontend/hooks/use-current-admin.ts

import { useDispatch, useSelector } from 'react-redux'

import { ReduxState } from '../store/store.js'
import { setCurrentAdmin } from '../store/actions/set-current-admin.js'
import { CurrentAdmin } from '../../current-admin.interface.js'

export type UseCurrentAdminResponse = [
  CurrentAdmin | null,
  (currentAdmin: CurrentAdmin | null) => CurrentAdmin | Record<string, unknown>
]

/**
 * @classdesc
 * Hook which allows you to get and set currentAdmin
 *
 * ### Usage
 *
 * ```javascript
 * import { useCurrentAdmin } from 'adminjs'
 *
 * const myComponent = () => {
 *   const [currentAdmin, setCurrentAdmin] = useCurrentAdmin()
 *   // ...
 * }
 * ```
 *
 * @class
 * @subcategory Hooks
 * @bundle
 * @returns {UseCurrentAdminResponse}
 * @hideconstructor
 */
function useCurrentAdmin(): UseCurrentAdminResponse {
  const currentAdmin = useSelector((state: ReduxState) => state.session)
  const dispatch = useDispatch()
  return [
    currentAdmin,
    (admin: CurrentAdmin | null): any => dispatch(setCurrentAdmin(admin)),
  ]
}

export {
  useCurrentAdmin,
  useCurrentAdmin as default,
}

/**
 * Result of the {@link useCurrentAdmin}.
 * It is a tuple containing value and the setter
 *
 * @typedef {Array} UseCurrentAdminResponse
 * @memberof useCurrentAdmin
 * @alias UseCurrentAdminResponse
 * @property {CurrentAdmin | null} [0]    current admin
 * @property {React.Dispatch<React.SetStateAction<CurrentAdmin>>} [1]    value setter compatible
 *                                                                       with react useState
 */

Directory Contents

Dirs: 6 × Files: 10

Name Size Perms Modified Actions
- drwxr-xr-x 2026-02-28 00:32:46
Edit Download
- drwxr-xr-x 2026-02-28 00:32:46
Edit Download
- drwxr-xr-x 2026-02-28 00:32:50
Edit Download
- drwxr-xr-x 2026-02-28 00:32:46
Edit Download
- drwxr-xr-x 2026-02-28 00:32:46
Edit Download
- drwxr-xr-x 2026-02-28 00:32:46
Edit Download
550 B lrw-r--r-- 2026-02-28 00:32:28
Edit Download
1.52 KB lrw-r--r-- 2026-02-28 00:32:46
Edit Download
946 B lrw-r--r-- 2026-02-28 00:32:50
Edit Download
1.13 KB lrw-r--r-- 2026-02-28 00:32:46
Edit Download
3.07 KB lrw-r--r-- 2026-02-28 00:31:56
Edit Download
2.28 KB lrw-r--r-- 2026-02-28 00:32:46
Edit Download
2.59 KB lrw-r--r-- 2026-02-28 00:32:46
Edit Download
890 B lrw-r--r-- 2026-02-28 00:32:46
Edit Download
2.39 KB lrw-r--r-- 2026-02-28 00:32:46
Edit Download
1.65 KB lrw-r--r-- 2026-02-28 00:32:46
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).