> ## Documentation Index
> Fetch the complete documentation index at: https://flatfileinc-remove-rss-json.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Transform and validate

> add validations and transformations to your listeners

<Snippet file="shared/dxpbanner.mdx" />

## Before you begin

To make working with event data inside a listener easy, Flatfile provides a
suite of Plugins.

<Note>
  Plugins extend the functionality of a listener. They are registered with the
  `listener.use()` function and fire when the listener receives a corresponding
  event.
</Note>

The Record Hook Plugin fires whenever a row of data (a Record) is added or
modified, allowing us to take action and perform a custom transformation.

### Import the recordHook plugin

<CodeGroup>
  ```js javascript theme={"system"}
  import { recordHook } from "@flatfile/plugin-record-hook";
  ```

  ```js typescript theme={"system"}
  import type { FlatfileRecord } from "@flatfile/plugin-record-hook";
  import { recordHook } from "@flatfile/plugin-record-hook";
  ```
</CodeGroup>

## Add your first transformation

Here's an example that modifies the first name value of a Record, converting it
to lowercase:

<Snippet file="quickstart/block1.mdx" />

As you can see, the `recordHook` has been configured to run on any Sheet
matching the slug "contacts". The second parameter to the recordHook is a
callback function where a Record, complete with it's own get and set methods, is
the incoming value.

<Info>Note: Unmodified rows do not trigger a Record Hook.</Info>

## Watch your data transform

Is your listener still running? If not, run `npx flatfile@latest develop` again.

Now, in your Workbook, add a new Record. Enter a capitalized value in the First
Name field, then click away so Flatfile knows you've finished your current edit.

Once your focus leaves the First Name field, an Event will trigger and the
`recordHook` will run the lowercase transformation you just configured.

## Add your first validation

You can also use a `recordHook` to help validate data.

For example, what if the first name in a Record is not a string? The current
code would not transform it, so let's add an error message to flag the Record.

<Snippet file="quickstart/block2.mdx" />

### Addl examples

<Tip>You can use any npm package in a plugin.</Tip>

The possible customizations are endless. Flatfile has a constantly expanding
library of
[transformation and validation plugins](https://flatfile.com/plugins/category/transform/)
that help you reshape data. You can add as many as you need to ensure your data
is clean and ready to be used.

For example, you could add code to validate a Record's email field:

<Snippet file="quickstart/block3.mdx" />

Remember that the recordHook plugin fires once per modified record, so you
should include the code for all transformations and validations you want on that
Record in the same `recordHook`.

## Watch your data validate

Check your listener is still running. If not, run `npx flatfile@latest develop`
again.

Now, in your Workbook, add or update a Record. Enter a number inside the
firstName field, or an invalid email address in the email field, then click away
so Flatfile knows you've finished your current edit.

See that error message? That's the result of your validation.

***

## Next steps

Now that you've added some transformations and validations, let's egress the
cleaned data: [Configure a submit Action](/learning-center/tutorials/projects/submit-action).
