i am very new to react. I as trying to add a signature module to a React component and everything worked fine so far. The module also offers a couple of methods, like clearing the canvas. My issue is, i have no idea where to set of the function in order to call it later in the render part. I have tried all possibilities (including useState, useRef) but cannot find a way to setup the function in a way so it is later.
So what i would like to access the clear method from the 3rd party library later in the return statement. I am aware useEffect was apparently not the right place to set the function up (however creating new SignaturePad works fine), but where would that be?
import SignaturePad from "signature_pad";
function OtherInfo(){
useEffect(()=> {
const canvas = document.getElementById("canvo")
const signaturePad = new SignaturePad(canvas)
// cannot be called later
const clear = signaturePad.clear()
})
return (
<div className="spefcontainer">
<input type="text" placeholder="More..." />
<input type="text" placeholder="Stuff..."/>
<canvas id="canvo"> </canvas>
<button onClick={clear}>Clear</button>
</div>
);}
export default OtherInfo;