rico345100 / react-multimedia-capture

react-multimedia-capture is Multimedia capturing module via React, using HTML5 MediaDevice and MediaRecorder API
49 stars 14 forks source link

how to access handleStart outside of MediaCapture. #6

Closed sravanshty closed 6 years ago

sravanshty commented 6 years ago

Hello,

As per the code we can access onStart={this.handleStart}......render = ({ start...}). But i just wanted to invoke handleStart function outside of . Like in some button click i just wanted to invoke. Could you please help me out this solution.

Thanks, Sravan Kumar Shetty

rico345100 commented 6 years ago

Hello.

To access internal method in object from out side, you can make external reference something like this:

let handleStartRef;

class SomeComponent extends Component {
    constructor() {
        handleStartRef = this.handleStart;
    }
    handleStart = () => {
        // ...
    }
    ...
}

// Outside of SomeComponent
// Make sure that at least one object instantiated SomeComponent constructor(class)
document.getElementById("some-button").onclick = function() {
    if(typeof handleStartRef === "undefined") return;
    handleStartRef();        // Invoke SomeComponent::handleStart
}

I won't sure the code works because it's just pseudo code, however this kind of approach will works because I already used some react apps.

rico345100 commented 6 years ago

I'm closing this, if you have any issue, you can freely re-open this.