This guide takes you through the process of creating a React project from scratch and integrating CreativeEditor SDK (CE.SDK) using NPM and a custom component. By the end, you’ll have a fully functional CE.SDK component running in your new React application, ready for customization.
Who Is This Guide For?
This guide is for developers who:
- Have some experience with React.
- Want to set up a new React project.
- Desire to build a React application with a fully-featured image and video editor component.
What You’ll Achieve
- Initialize a new React project using Vite
- Install CE.SDK via NPM.
- Integrate CE.SDK into your new React project.
- Use CE.SDK to build a basic creative editor React component with default settings.
Prerequisites
Before you begin, ensure you meet these prerequisites:
- Node.js v20+ and NPM 10+ installed locally. Download the latest LTS version of Node.js and NPM.
- A valid CE.SDK license key (start a free trial to retrieve one).
Step 1: Set Up a New React Project
Using a build tool like Vite, Parcel, or RSBuild is the recommended way to initialize a new React project. In this guide, you’ll use Vite.
Run the following Vite command to create a new blank React project called my-react-app:
npm create vite@latest my-react-app -- --template react
Or, equivalently, on Windows:
npm create vite@latest my-react-app --template react
A new React project will be created in the my-react-app folder. Move into the project folder in the terminal:
cd my-react-app
This is the file structure it should contain:
my-react-app/├── public/ # Static assets│ └── vite.svg # Default Vite logo│├── src/ # Source code│ ├── assets/ # Additional static assets│ │ └── react.svg # React logo│ ││ ├── App.css # Styles for the main App component│ ├── App.jsx # Main React component│ ├── index.css # Global styles│ └── main.jsx # Entry point for the React app│├── .gitignore # Git ignore rules├── eslint.config.js # ESLint configuration├── index.html # Main HTML file (Vite entry point)├── package.json # Project dependencies and scripts├── README.md # Project documentation└── vite.config.js # Vite configuration
Install the project’s dependencies via NPM with:
npm install
Step 2: Install CE.SDK
Add CreativeEditor SDK to your project’s dependencies by installing the @cesdk/cesdk-js
NPM package:
npm install @cesdk/cesdk-js
Step 3: Create Your Creative Editor Component
In the src/
folder of your new React project, create a new file named CreativeEditorSDK.jsx
defining the following component:
import CreativeEditorSDK from '@cesdk/cesdk-js';
import { useEffect, useRef, useState } from 'react';
// configure CreativeEditor SDKconst config = { license: '<YOUR_LICENSE_KEY>', // replace it with a valid CE.SDK license key callbacks: { onUpload: 'local' }, // enable local file uploads in the Asset Library};
export default function CreativeEditorSDKComponent() { // reference to the container HTML element where CESDK will be initialized const cesdk_container = useRef(null); // define a state variable to keep track of the CESDK instance const [cesdk, setCesdk] = useState(null);
useEffect(() => { // prevent initialization if the container element is not available yet if (!cesdk_container.current) { return; }
// flag to keep track of the component unmount let cleanedUp = false; // where to store the local CE.SDK instance let instance;
// initialize the CreativeEditorSDK instance in the container HTML element // using the given config CreativeEditorSDK.create(cesdk_container.current, config).then( async _instance => { // assign the current CD.SDK instance to the local variable instance = _instance;
if (cleanedUp) { instance.dispose(); return; }
// do something with the instance of CreativeEditor SDK (e.g., populate // the asset library with default / demo asset sources) await Promise.all([ instance.addDefaultAssetSources(), instance.addDemoAssetSources({ sceneMode: 'Design' }), ]);
// create a new design scene in the editor await instance.createDesignScene();
// store the CESDK instance in state setCesdk(instance); }, );
// cleanup function to dispose of the CESDK instance when the component unmounts const cleanup = () => { // clear the local state and dispose of the CS.SDK instance (if it has been assigned) cleanedUp = true; instance?.dispose(); setCesdk(null); };
// to ensure cleanup runs when the component unmounts return cleanup; }, [cesdk_container]);
return ( // the container HTML element where the CESDK editor will be mounted <div ref={cesdk_container} style={{ width: '100vw', height: '100vh' }} ></div> );}
Step 4: Use the Creative Editor Component
Import CreativeEditorSDKComponent
in the App.jsx
file:
import { CreativeEditorSDKComponent as CreativeEditorSDK } from './CreativeEditorSDK';
Then, you can render the component on the page by adding it to the JSX as follows:
<CreativeEditorSDK />
App.jsx
will contain:
// other imports...import { default as CreativeEditorSDK } from './CreativeEditorSDK';
function App() { // state management ...
return ( <> {/* other components.. */} <CreativeEditorSDK /> {/* other components.. */} </> );}
export default App;
Step 5: Serve the React Project Locally
Run the project locally using the development server provided by Vite. Starting the local server with the following command:
npm run dev
By default, the React app will be accessible on your localhost at http://localhost:5173/
.
Step 6: Test the Integration
- Open
http://localhost:5173/
in your browser. - A fully functional CE.SDK editor should appear.
Troubleshooting & Common Errors
❌ Error: Identifier 'CreativeEditorSDK' has already been declared
- Ensure that the name of your custom creative editor component function isn’t
CreativeEditorSDK
, as it conflicts with the class imported from@cesdk/cesdk-js
.
❌ Error: The requested module '/src/CreativeEditorSDK.jsx' does not provide an export named 'CreativeEditorSDKComponent'
- Make sure that
CreativeEditorSDKComponent
is imported directly or as a default import, not with a named import. That’s required because theCreativeEditorSDK.jsx
file doesn’t define a named export.
❌ Error: The following dependencies are imported but could not be resolved: @cesdk/cesdk-js
- Check that you’ve correctly installed CE.SDK using
npm install @cesdk/cesdk-js
.
❌ Error: Editor engine could not be loaded: The License Key (API Key) you are using to access CE.SDK is invalid
- Double-check that your CE.SDK license key is valid and hasn’t expired.
❌ Editor does not load
- Check the browser console for any errors.
- Verify that your component paths and imports are correct.
Next Steps
Congratulations! You’ve successfully integrated CE.SDK into a new React project. Now, take some time to explore the SDK and proceed to the next steps whenever you’re ready: