Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
379 views
in Technique[技术] by (71.8m points)

reactjs - How can I call another function inside of arrow function in JSX?

I have a component that uses a callback function, and when it's executed I have it render a video tag. But I also want to use ipcRenderer.send right after the video tag, but don't know how to write it properly to make it happen.

        <div className="main-user-video">
          {/* TODO: Use WebRTC.onCallUserAdded to add another and add another video with the new remoteStream */}
              <video
                id="video_player"
                className="main-user-video"
                // style={
                //   this.state.knocking.callAccepted
                //     ? null
                //     : { filter: "grayscale(100%)" }
                // }
                controls={false}
                ref={this.remoteVideo}
                autoPlay={true}
              ></video>
                {WebRTC.onCallUserAdded((err, callId, userId, audio, video, remoteStream, usersInCall) =>
                  <video
                  id="video_player"
                  className="main-user-video"
                  controls={false}
                  ref={remoteStream}
                  autoPlay={true}
                ></video>
                {(usersInCall > 2) ? electron.ipcRenderer.send("MULTI-PARTY-CALL") : null}
                )}
        </div>

Right after that second video tag is where I want to use ipcRenderer.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

arrow functions are shorthand for a function that returns values.

() => <video/>

equals

() => {
  return <video/>
}

You can do whatever you want in the block before return

() => {
  // call function or any process
  return <video/>
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...