chayns-hooks
Welcome to chayns-hooks 👋
Makes the chayns-js API easier to consume in your react components.
Install
yarn add chayns-hooks
or
npm install chayns-hooks
Please note that this needs the chayns-js API to be available on the window object and chayns.ready
should be finished.
The instructions for how to get started with the chayns-js
API can be found here.
🤝 Contributing
Contributions, issues and feature requests are welcome!
Feel free to check issues page.
Show your support
Give a ⭐️ if this project helped you!
📝 License
Copyright © 2020 Leo Driesch.
This project is MIT licensed.
chayns-hooks
Index
Interfaces
Type aliases
Functions
Type aliases
PossiblyEmptyString
Ƭ PossiblyEmptyString: string
VisibilityEffect
Ƭ VisibilityEffect: function
A function that can respond to the change of the visibility status of your page.
param
This parameter expresses wether the last visibility status update
indicates that the page is now shown or not.
Type declaration:
▸ (isShown
: boolean): void
Parameters:
Functions
useAdminMode
▸ useAdminMode(): AdminModeHookReturnValue
Using this hook will subscribe your component to the current state of the admin
mode.
Returns: AdminModeHookReturnValue
An object that can be destructed to get access to the current status
of the admin mode and functions to manually activate or deactivate the admin mode.
useChaynsUser
▸ useChaynsUser(): ChaynsUser
Returns the current user object and will update the user on access
token change.
Returns: ChaynsUser
The user object for the currently logged in user.
useVisibilityEffect
▸ useVisibilityEffect(effect
: VisibilityEffect): void
This hook can execute side effects when the visibility status of your page changes.
Parameters:
Name | Type | Description |
---|
effect | VisibilityEffect | This function will be called when the visibility changes and can respond to the change by executing side effects. Consider using useCallback with this function, otherwise the listener will be attached and detached on every render. |
Returns: void
Nothing. Use it similarly to useEffect
.
Interface: AdminModeHookReturnValue
Hierarchy
Index
Properties
Properties
activateAdminMode
• activateAdminMode: function
Calling this function will activate the admin mode, if it is currently
inactive. Otherwise it will do nothing.
Type declaration:
▸ (): void
deactivateAdminMode
• deactivateAdminMode: function
Calling this function will deactivate the admin mode, if it is active.
Otherwise it will do nothing.
Type declaration:
▸ (): void
isAdminMode
• isAdminMode: boolean
Indicates if the user is currently in admin mode or not.
Interface: ChaynsUser
Hierarchy
Index
Properties
Properties
adminMode
• adminMode: boolean
Wether the admin mode is currently active or not. Be careful with this, as
it might be stale. Use the useAdminMode
hook when you need access to this
information.
Optional
firstName
• firstName? : undefined | string
groups
• groups: UACGroup[]
This contains the groups for a user. Will be an empty array if the user is
not logged in.
id
• id: number
The user-id.for the currently logged in user. Careful: If no user is logged
in, this will be 0
(not null
or undefined
)
isAdmin
• isAdmin: boolean
isAuthenticated
• isAuthenticated: boolean
Optional
lastName
• lastName? : undefined | string
name
• name: PossiblyEmptyString
The name for the currently logged in user. Careful: If no user is logged
in, this value will be an empty string.
personId
• personId: PossiblyEmptyString
The person-id for the currently logged in user. Careful: If no user is logged
in, this value will be an empty string.
tobitAccessToken
• tobitAccessToken: PossiblyEmptyString
The access token for the currently logged in user. Careful: If no user is
logged in, the value will be an empty string.
Interface: UACGroup
Hierarchy
Index
Properties
Properties
id
• id: number
isActive
• isActive: boolean
Optional
isSystemGroup
• isSystemGroup? : undefined | false | true
Optional
name
• name? : undefined | string