Skip to main content

useReplit() Hook

The useReplit() hook establishes the handshake between the Replit and the extension and passes the API wrapper for usage inside a React component.

Usage

import { useReplit } from '@replit/extensions-react';

const Component = () => {
const { replit, status, filePath, error } = useReplit();

...
}

Signature

function useReplit(init?: {
permissions: Array<string>;
}): UseReplitInitialized | UseReplitPreInitialization | UseReplitFailure;

Result

PropertyTypeDescription
statusHandshakeStatusA string indicating the status of the handshake between Replit and the Extension
errorstring | nullIf the handshake has failed, error is a string indicating the error message
filePathstring | nullIf the handshake has succeeded, filePath points to the current file the user is focusing
replittypeof replitIf the handshake has succeeded, replit is the API wrapper for the entire @replit/extensions module

Types

HandshakeStatus

An enumerated set of values for the handshake status.

KeyValue
Ready"ready"
Error"error"
Loading"loading"

UseReplitReady

If the handshake between Replit and the Extension has been established successfully

PropertyType
statusHandshakeStatus.Ready
errornull
filePathstring
replittypeof replit

UseReplitLoading

The default handshake status, before initialization has been established.

PropertyType
statusHandshakeStatus.Loading
errornull
filePathnull
replitnull

UseReplitFailure

If the handshake has failed.

PropertyType
statusHandshakeStatus.Error
errorstring
filePathnull
replitnull
Was this helpful?