-
Notifications
You must be signed in to change notification settings - Fork 52
Open
Description
Is there any way to pass p5 back to the parent component as a ref? I'm trying to accomplish something like this:
const sketch: Sketch = (p5) => {
p5.setup = () => //...
p5.updateWithProps = (props: any) => {
if( !props.ref?.current ) {
props.ref.current = p5
}
}
}
const Fx = () => {
const p5ref = useRef<P5CanvasInstance>(null)
return (
<>
<P5Canvas sketch={sketch} ref={p5ref} />
<button onClick={() => p5ref.current?.clear()} >Clear</button>
</>
)
}Every time I try this, I start getting wild errors regarding Named export 'GIFEncoder' not found. The requested module 'gifenc' is a CommonJS module
(If I'm not nuts about this idea, I think it would be nice if this could exist in the constructor, where P5Canvas automatically initializes a ref when one is detected, rather than clumsily putting that in updateWithProps.)
Metadata
Metadata
Assignees
Labels
No labels