C
C
campus12018-07-16 19:14:07
React
campus1, 2018-07-16 19:14:07

How to make collapse on click?

Hello.
Trying to make a small accordion using material-ui.
So far I have done this: https://codesandbox.io/s/rj1yqr28mq
But when you click on the same div, it does not collapse, because the panel is remembered in the state. Tell me how you can solve this problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Spirin, 2018-07-16
@campus1

handleClick = panel => {
  const panelName = this.state.panelName === panel ? null : panel;
    
  this.setState({
    panelName,
  });
};

R
Roman Aleksandrovich, 2018-07-16
@RomReed

https://codesandbox.io/s/pjpnvonzz7

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question