Hey Eduardo,
There's a library on npm, https://github.com/typescriptlibs/tsl-apple-cloudkit, that allows you to import the CloudKit JS library into your app using an ES6 import like so:
import * as CloudKit from 'tsl-apple-cloudkit';
Your bundler will then combine that with your other dependencies (like React) and your application code, rather than having to include the CloudKit JS script tag separately and then wait for it to load.
tsl-apple-cloudkit also gives you TypeScript types for most of the library functions.
I've written an example app using tsl-apple-cloudkit + Next.js + React + TailwindCSS: https://github.com/steveharrison/cloudkitjs-examples/tree/main/nextjs-cloudkit.
It's definitely not intuitive using CloudKit JS, so I've written a guide on it here: https://www.steveharrison.dev/exploring-cloudkit-js/. (It includes a section on the Next.js demo app.)
I've been accessing CloudKit using a client-side token, and this works perfectly fine if you just need the data on the Front End. If you want to manipulate the data on the Back End / combine with other server-side logic then the server-side token would be a good choice for that.
Hope this helps—let me know if you have any more questions!