The following example demonstrates how to use row hooks to validate data against an external API.
For more information on row hooks, see the Row Hooks documentation.
Although it’s not required to use async/await with hooks, we recommend you use it with an external API call.
export const fields = [
  {
    label: 'Email',
    key: 'email'
  }
];

let hasFetchedData = false;
let serverResults;

dromo.registerRowHook(async function (record) {
  const newRecord = record;
  if (!hasFetchedData) {
    await fetch('https://my-json-server.typicode.com/dromoio/docs-email-api/leads', {
      method: 'GET'
    })
      .then((response) => response.json())
      .then(function (json) {
        serverResults = json.map((record) => {
          return record['email'];
        });
        hasFetchedData = true;
      });
  }
  if (serverResults.includes(newRecord.row['email'].value)) {
    newRecord.row['email'].info = [
      {
        message: 'Duplicate record. This user is already in the database.',
        level: 'error'
      }
    ];
  }
  return newRecord;
});