React Components
Configure your Space in React
Components
FlatfileProvider
FlatfileProvider
is a comprehensive React component designed for integrating Flatfile’s import capabilities into your application.
It can be initialized using either a publishableKey
or an accessToken
, providing flexibility depending on your authentication flow.
The component allows for extensive customization of the embedded iFrame through styling parameters, ensuring that the import modal matches your application’s aesthetics.
It maintains the configuration necessary for creating and managing Spaces, Workbooks, and Documents within Flatfile.
Additionally, FlatfileProvider
manages a client-side listener to handle browser-based events, ensuring a seamless user interaction with the import process.
Learn more about the FlatfileProvider
Space
The Space
component from the @flatfile/react
package is utilized to define a collaborative environment or workspace within Flatfile’s import system. It can be configured to create a new space or to reuse an existing one by providing a space ID.
Main Props
config
: Sets up the configuration for a new space, including theming and metadata.id
: An optional prop that, when provided, indicates the specific existing space to be reused instead of creating a new one.
Learn more about the Space
Example usage for creating a new space:
When you want to re-use a space, you’ll need to pass an accessToken
to the FlatfileProvider
, then this is where you’ll add the id
of the Space you want to re-use.
Workbook
Configures all Workbook Creation request data and a new onRecordHook helper function
onSubmit
and a new onRecordHooks
helper can be added to the Workbook. A Workbook object containing the sheets can be passed along in the config
.
onRecordHooks
takes an array of record hooks. Each one can take a slug for manually setting each per sheet. Otherwise, if no slug is added, it will apply the record hook to the corresponding sheet in the Workbook index.
Learn more about the Workbook
Sheet
The Sheet
component from the @flatfile/react
package integrates Flatfile’s data import functionality into React applications. It simplifies configuring the data import process and managing the lifecycle of data submission and record handling.
Main Props
config
: Defines the structure and settings of the data to be imported.onSubmit
: A callback function that is triggered upon successful data submission.onRecordHook
: A function that allows for custom record manipulation during the import process.submitSettings
: Customizes the behavior of the data submission process.
The Sheet option is similar to the Simplified SDK Approach.. Learn more about the Sheet
Example usage:
Document
Configures a Document to be added to the Space. Takes a simple Flatfile.DocumentConfig
as a param.
React Hooks 🪝
useFlatfile
This Hook exposes a few handy functions for integrating with the FlatfileProvider
openPortal()
: Opens the iFrame. This will create the underlying Space, Workbook and configure if necessary or open the Space provided.closePortal()
: Closes the iFrame.open
: current open statuslistener
: Current listenersetListener()
: manually sets the listener
useListener
This Hook exposes and adds any logic to the current listener with conditional dependencies
usePlugin
This Hook exposes and adds a plugin to the current listener with conditional dependencies
useEvent
This Hook exposes any event coming from the iFrame to respond to with proper filtering