...

Filestack for React ⚛️

Overview

The filestack-react library is a component-based wrapper for the core filestack-js SDK. It’s designed to help you integrate Filestack’s file handling services into your React applications with minimal effort and a familiar developer experience. You can implement the powerful Filestack Picker and its features in just a few lines of code.

Usage

Compatibility Notice: The filestack-react library currently supports React versions 18.3+ and 19. Node (to build/develop): >=18. If you are starting a new project, please ensure you are using a compatible version of React.

Installation

Install the package from NPM.
npm install filestack-react filestack-js
As of version 7, the filestack-js is a peer dependency (^4.0.0). Skipping it causes npm to warn about an unmet peer dependency, and the picker does not initialize.

Implementation

Import a picker component and add it to your app. The only required prop is your Filestack API key.
import { PickerOverlay } from 'filestack-react';

const App = () => (
  <PickerOverlay
    apikey={'YOUR_API_KEY'}
    onUploadDone={(res) => console.log(res)}
  />
);

Component Props

Customize the picker’s behavior and appearance using these props.
Key Type Required Description
apikey String Yes* Your Filestack API key. (*Optional if a FilestackProvider supplies it.)
clientOptions Object No Options to initialize the filestack-js client. See docs.
pickerOptions Object No Controls the picker’s behavior and UI. See docs for all available settings.
onSuccess Function No Deprecated A function called after a successful action. Use onUploadDone instead.
onUploadDone Function No Callback function that runs when all files have been successfully uploaded. Receives the result object.
onError Function No Callback function that runs when an error occurs.

Picker Components & Examples

The library provides three main components to render the picker in different ways.

PickerOverlay

Renders the picker in a modal that overlays your application.
import { PickerOverlay } from 'filestack-react';

<PickerOverlay apikey={'YOUR_APIKEY'} />

PickerInline

Renders the picker directly inside a container in your application’s DOM.
import { PickerInline } from 'filestack-react';

<PickerInline apikey={'YOUR_APIKEY'} />

PickerDropPane

Renders a drag-and-drop area for uploads.
import { PickerDropPane } from 'filestack-react';

<PickerDropPane apikey={'YOUR_APIKEY'} />

Custom Container

To embed the PickerInline or PickerDropPane in a specific element, pass that element as a child.

<PickerInline apikey={'YOUR_APIKEY'}>
  <div id="my-filestack-container" style={{ height: '400px' }} />
</PickerInline>

Using the filestack-js Client

For advanced use cases, you can access the underlying filestack-js client instance directly. This allows you to use methods like transform(), storeURL(), and remove().

import { client } from 'filestack-react';

const filestackClient = client.init('YOUR_APIKEY');

filestackClient.transform(handle, { resize: { width: 100 } })
  .then(res => {
    console.log(res);
  });

Using the FilestackProvider Context

Introduced in v7, the FilestackProvider context lets users save time by automatically syncing the same configuration across their picker components.

Previously, rendering several pickers in the same app required that every picker component have its own apikey, clientOptions, and callback props. Even when the pickers had identical configurations. Starting in version 7.0.0, users can use the FilestackProvider to wrap an app (or any subtree) and hold the configuration in context. Meaning that any picker components underneath it automatically read from the provider, and only fallback to their own prop if explicitly indicated.

This is a useful tool for those users who have apps that render the picker in multiple places, such as a header upload button and a setting page avatar picker. It is no longer necessary to manually keep configurations in sync. Now you can set it once at the provider level and have it apply at the per-component level. If needed, users can override it per-component for when the occasion requires different configurations. Additionally, the editor flags a mismatched prop before running the app. 

See the example below to learn how to wrap your app once so that every picker component underneath it inherits the same configuration.

import { FilestackProvider, PickerDropPane } from 'filestack-react';

function App() {
  return (
   <FilestackProvider 
    apikey={'YOUR_API_KEY'}
    onUploadDone={(result) => console.log(result.filesUploaded)}
   >
     <UploadWidget  />  
   </FilestackProvider>
);
}
// No need to repeat apikey or onUploadDone here - inherited from FilestackProvider
function UploadWidget() {
return <PickerDropPane />;
}
Scalar values such as apikey, onUploadDone, onError, and onSuccess set directly on a picker override the provider’s set values. And pickerOptions and clientOptions have the provider as the base and the component’s options on top.

TypeScript

Along with v7, the entire SDK has been changed to support TypeScript/TSX (previously JavaScript/JSX). Type declaration files (.d.ts) are now included in the package. Ensuring autocomplete and type safety from the start. 

The package bundles its own declarations. Install it, import it, and ready to go. No @types/* needed, see an example below.

import {  
  PickerOverlay,
  FilestackProvider,
type PickerOverlayProps,
type PickerResponse,
type PickerOptions,
type ClientOptions
} from 'filestack-react';

const pickerOptions: PickerOptions = { maxFiles: 5, accept: ['image/*']};
const clientOptions: ClientOptions = { cname: 'cdn.example.com' };

const handleUploadDone = (res: PickerResponse) => {
 res.filesUploaded.forEach((file) => console.log(file.url));
};

const App = () => (  
 <FilestackProvider apikey={process.env.REACT_APP_FILESTACK_KEY!}>
   <PickerOverlay
     pickerOptions={pickerOptions} 
     clientOptions={clientOptions}
     onUploadDone={handleUploadDone}
     onError={ (err) => console.error(err)}
 /> 
 </ FilestackProvider> 
);

Since PickerOptionsClientOptions, and PickerResponse come from filestack-js, you get autocomplete on every nested option (maxFilesacceptfromSourcestransformations, and the rest).

Migration Guides

Migrating from v6 to v7

Note: Read this carefully before upgrading.

Most applications using v6 require two main changes before upgrading to v7: installing the filestack-js and renaming one callback. 

The filestack-js component is not a peer dependency, which must be installed manually alongside filestack-react. Not doing so results in a failed build or an SDK runtime error.
Follow these steps to ensure a successful upgrade.
  1. Install it by using the following command:
npm install filestack-react@7.0.0 filestack-js@^4.0.0

2. Check your React and Node versions. Note that the React peer dependency range has changed and now requires react:^18.3.1 || ^19.0.0 and react-dom:^18.3.1 || ^19.0.0

Note: If you are using a version of React lower than 18.3.1, you must first upgrade to 18.3.1. React 16 and 17 are no longer supported.

3. Update the Filestack dependencies by using the following command (Ensure the Node version is 18.3.1 or higher):

npm install filestack-react@7.0.0 filestack-js@^4.0.0
# or
yarn add filestack-react@^7.0.0 filestack-js@^4.0.0
4. Remove @types/filestack-react from the product using the command below. Types now ship with the package.
npm uninstall @types/filestack-react
5. Ensure to add filestack-js explicitly to the package.json; it is now a peer dependency and is not installed automatically as a transitive dependency.
6. Check the usePicker and picker component callbacks. If using both onSuccess and onUploadDone, ensure your app behaves correctly now that only onUploadDone fires when both are present.
7. Remove any workarounds for SSR, Next.js, or Vite issues. The use client directives and corrected ESM/CJS exports mean previous workarounds for App Router or Vite resolution errors are no longer needed.

8. Run your test suite. With the TypeScript rewrite, you may see new type errors surfaced in your own code where prop types were previously unchecked at compile time.

Key props have been renamed for consistency.
Old Prop (v6) New Prop (v7) Comment
apikey, pickerOptions, clientOptions same Unchanged.
onUploadDone, onError same Unchanged.
onSuccess onUploadDone onSuccessis deprecated but it still works.
filestack-js bundled as a dependency filestack-js ^4 peer dependency Install it in your apps.
React 16/17/18 React 18.3+/19
plain JavaScript TypeScript types included Drop @types/filestack-react.

Migrating from v3/v4 to Latest

Key props have been renamed for consistency.
Old Prop (v3/v4) New Prop Comment
actionOptions pickerOptions Unified naming for picker configuration.
action N/A The default picker action is now always ‘pick’.
customRender N/A Clients are now responsible for rendering logic.
componentDisplayMode N/A Render logic is handled by the client.

Migrating from v1/v2 to v3+

Props were re-structured for clarity.
Old Prop (v1/v2) New Prop Comment
mode actionOptions Emphasizes association with a picker ‘action’.
options.security clientOptions.security Security options are now grouped under clientOptions.
buttonText componentDisplayMode.customText Use the componentDisplayMode option. (Deprecated in v4+)
buttonClass componentDisplayMode.customClass Use the componentDisplayMode option. (Deprecated in v4+)
render customRender Use the customRender prop. (Deprecated in v4+)

More Resources

  • Live Demo: Try the picker on CodePen (Note: this demo may not reflect the latest version).
  • Development: All components are located in the src/picker/ directory of the repository. Run npm run build to compile changes.
  • Contribution: Contributions and ideas are welcome! The project follows the conventional commits specification.