Skip to content

onStop callback not refreshed on componentUpdate #108

Open

Description

@Heedster

The function that I pass to on onStop changes because of changes in its internal dependency, but onStop always calls the first reference passed into .

I looked into the code and it seems to agree with my inference.
MicrophoneRecorder instance is created on componentDidMount of ReactMic Component and not on subsequent rerenders, so its not getting new onSave functions.

Surprisingly, the componentDidUpdate invokes microphoneRecorder.stopRecording(onStop), but the stopRecording function in MicrophoneRecorder does not even accept a param.

Seems like onStop was supposed to changed, but got missed somewhere in the implementation

Activity

  1. riwu commented on Jan 19, 2021

    @riwu

    Ran into the same issue. Spent an hour debugging why the onStop callback is using old values...

  2. artemov34 commented on Mar 30, 2021

    @artemov34

    crutch

    useEffect(() => {
            Object.assign(window, { globalFormChange: formData});
        }, [formData]);
    
      
        const recordStop = (data: any) => {
            handleSubmit({...(window as any).globalFormChange, audio_blob: blobToFile(data.blob, 'audio')})
        }
    
  3. adnakate commented on Apr 28, 2021

    @adnakate

    Facing the same issue. Spent hours on it. I don't like the solution using global variable.

  4. HackerAIOfficial commented on Mar 31, 2023

    @HackerAIOfficial

    I'm new to React learning useEffect and hook stuff, this was very confusing guys :D
    I guess it's an optimization that you do, at least I had to learn more about React.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions