Created
March 15, 2024 12:54
-
-
Save Karan-Palan/9a3f9c72b59153c0516471d3dc8a43b3 to your computer and use it in GitHub Desktop.
Example code for Wrapper component in Music blocks v4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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