Skip to main content

Hooks reference

Retool provides a set of custom React hooks, which give your app access to certain information and actions on the Retool platform. These hooks are stored in your app's frontend/hooks directory.

To update your app to use a hook, describe what you want in a prompt, or call one manually.

useCurrentUser​

useCurrentUser returns the user who is signed in to the app.

ValueTypeDescription
userObject or nullThe current user. This value is null while the request is in progress, and null if the request fails. Learn more about the Current User object.
loadingBooleanWhether the request is in progress.
Example: Show the user's name
function Greeting() {
const { user, loading } = useCurrentUser()

if (loading) return <p>Loading...</p>
return <p>Welcome, {user?.firstName}</p>
}

User actions​

The following hooks provide access to user and account actions.

useRetoolAccountAuth​

useRetoolAccountAuth returns functions that act on the user's Retool account. It returns an object with the following function:

FunctionTypeDescription
logout() => Promise<void>Signs the user out of Retool. Redirects the user to the login page.
Sign-out button
function SignOutButton() {
const { logout } = useRetoolAccountAuth()
const [error, setError] = useState(null)

return (
<>
<button onClick={() => logout().catch((err) => setError(err.message))}>
Sign out
</button>
{error && <p>{error}</p>}
</>
)
}

useRetoolAppsAndFolders​

useRetoolAppsAndFolders returns the apps and folders the current user can access. It uses the same permission check as the Retool homepage, so the user sees the same items in both places. Use it to build a custom landing page.

ValueTypeDescription
dataObject or undefinedAn object with an apps array and a folders array. This value is undefined until load succeeds.
loadingBooleanWhether a request is in progress.
errorError or nullThe error from the most recent request. This value is null if the request succeeded or hasn't started.
load() => PromiseRequests the apps and folders. The promise resolves with the same object that data holds. If the request fails, the promise resolves undefined and sets error instead of throwing.

Each item in apps has the following properties:

PropertyTypeDescription
idStringThe unique identifier.
nameStringThe app name.
descriptionString or nullThe app description.
shortlinkString or nullThe app's short URL.
folderIdNumber or nullThe ID of the folder that contains the app.
protectedBooleanWhether the app is protected.
isMobilePageBooleanWhether the app is a mobile app.
isModuleBooleanWhether the app is a module.
syncedBooleanWhether the app is synced.
accessLevelStringThe user's access level for the app.
createdAtStringThe date and time the app was created.
updatedAtStringThe date and time the app last changed.

Each item in folders has the following properties:

PropertyTypeDescription
idNumberThe unique identifier.
nameStringThe folder name.
folderTypeStringThe folder type.
isSystemFolderBooleanWhether Retool created the folder automatically.
parentFolderIdNumber or nullThe ID of the parent folder.
accessLevelStringThe user's access level for the folder.
createdAtStringThe date and time the folder was created.
updatedAtStringThe date and time the folder last changed.
List the apps a user can open
function AppLauncher() {
const { data, loading, error, load } = useRetoolAppsAndFolders()

useEffect(() => {
load()
}, [load])

if (loading) return <p>Loading...</p>
if (error) return <p>{error.message}</p>

return (
<ul>
{data?.apps.map((app) => (
<li key={app.id}>{app.name}</li>
))}
</ul>
)
}

Limitations​

The following limitations apply to hooks:

  • useRetoolAppsAndFolders and useRetoolAccountAuth are not supported in embedded apps. The request fails.
  • Hooks do not provide coverage for other user actions available in classic apps, such as logging in, resetting a password, or claiming an invitation.