Created
April 1, 2024 20:13
-
-
Save Karan-Palan/222c3cba7883d0ce00013150d8796b96 to your computer and use it in GitHub Desktop.
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'; | |
const BuilderWrapper: React.FC = () => { | |
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: Event) => { | |
// Handle events from the Project Builder API | |
if (builderInstance) { | |
builderInstance.handleCustomEvent(); | |
} | |
}; | |
return null; // You might return something meaningful here, depending on your application logic | |
}; | |
export default BuilderWrapper; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment