Is this kind of writing function is correct in react?

Hello,

Is this kind of writing function is correct in react:

 onFileChangeName = event => {
        this.setState({ selectedFileName: event.target.files[0].name });
    };

and then use first function in another function:

 onNavToEditor = async () => {

        this.onFileChangeName();
       
        this.setState({ redirect: "/ImageEditor" });


    };

thanks,
Saeed

onFileChangeName is a handler function it needs to be called by an event listener (e.g. onClick or whatever).

It takes an event and you do not have access to that event inside the async function (you are not passing anything as an argument to the function).

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.