Skip to content

Instantly share code, notes, and snippets.

@Karan-Palan
Created March 15, 2024 12:54
Show Gist options
  • Save Karan-Palan/9a3f9c72b59153c0516471d3dc8a43b3 to your computer and use it in GitHub Desktop.
Save Karan-Palan/9a3f9c72b59153c0516471d3dc8a43b3 to your computer and use it in GitHub Desktop.
Example code for Wrapper component in Music blocks v4
import React, { useState, useEffect } from 'react';
import ProjectBuilder from 'musicblocks-v4-builder-framework';
interface BuilderWrapperProps {}
const BuilderWrapper: React.FC<BuilderWrapperProps> = (props) => {
const [builderInstance, setBuilderInstance] = useState<ProjectBuilder | null>(null);
useEffect(() => {
// Initialize the Project Builder instance
const builderInstance = new ProjectBuilder();
// Add event listeners for communication with other components
builderInstance.addEventListener('event', handleEvent);
// Set the state to update the component with the initialized instance
setBuilderInstance(builderInstance);
return () => {
// Remove event listeners when component unmounts
builderInstance.removeEventListener('event', handleEvent);
};
}, []);
const handleEvent = (event: any) => {
// Handle events from the Project Builder API
if (builderInstance) {
builderInstance.handleCustomEvent();
}
};
return null;
};
export default BuilderWrapper;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment