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
3.4k views
in Technique[技术] by (71.8m points)

reactjs - How can I fix this long delay in a Material-UI ToggleButtonGroup?

I'm migrating an app from React-Bootstrap to Material-UI. Mostly a positive experience, but my toggle button group is very sloooooow. Like 3+ seconds to respond to to a click. I thought if I stripped it down to a minimum the problem would go away, but it didn't. (It did improve; I think the delay before was 5-7 seconds.) Here is the sandbox.

It displays two toggle buttons, "MUTE" and "ON". If you click a button it takes 3+ seconds for the event handler to log the call on the console. Mostly it takes that amount of time to change state visually, though in some cases, one of the buttons changes state immediately when you click it, while the other delays before changing state. Even in that case, though, the console log is delayed, and changing back to the other button is delayed.

Here is the JSX of the component:

    <ToggleButtonGroup value={toggle} onChange={onMicToggle} exclusive>
      <ToggleButton value="mute">mute</ToggleButton>
      <ToggleButton value="on">on</ToggleButton>
    </ToggleButtonGroup>

And here is the calling code:

    <MicControl
      toggle={toggle}
      onMicToggle={(e, v) => {
        setToggle(v);
        console.log("onMicToggle:", e, "Value:", v);
      }}
    />

Any fixes or workarounds greatly appreciated!


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

1 Reply

0 votes
by (71.8m points)

Just remove console.log("onMicToggle:", e, "Value:", v); from your onChange callback function


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

...