Achieve the multi-selection effect of div (similar to the multi-selection of checkbox, which can be selected or deselected)

export default class App extends React.Component {
  state = {
    expand: flase,
    renList: [],
  }
  handleCheck = value => {
    const { expand, renList } = this.state
    this.setState({ expand: !expand })
    renList.push(value)
  }

  render() {
    return (
      <div>
        {list.map(subItem => (
          <div>
            <div
              className={`${css.sunKind} ${
                this.state.expand === true ? css.active : null
              }`}
              onClick={() => this.handleCheck(subItem)}
            >
              {subItem.name}
            </div>
          </div>
        ))}
      </div>
    )
  }
}

after rendering the content, if you want to click on one of them, it will be selected, then add the class name active to the setting you click, and add it to renList, and then click again to remove the selected state and remove it from renList, similar to the effect of checkbox multi-selection. Now it is somewhat confusing, how do you need to modify it? Thank you very much!

Feb.23,2022

export default class SelectDiv extends Component {
  state = {
    selects: [],
    renList: [{ name: 'n1' }, { name: 'n2' }, { name: 'n3' }],
  }
  handleCheck = ({ name }) => {
    this.setState(({ selects }) => ({
      selects: selects.includes(name)
        ? selects.filter(item => item !== name)
        : [...selects, name],
    }))
  }
  selectAll = () => {
    this.setState(({ renList }) => ({
      selects: renList.map(item => item.name),
    }))
  }
  cancelSelectAll = () => {
    this.setState(() => ({
      selects: [],
    }))
  }
  render() {
    const { selects: selects, renList } = this.state
    return (
      <div>
        <button onClick={this.selectAll}></button>
        <button onClick={this.cancelSelectAll}></button>
        {renList.map(subItem => (
          <div>
            <div
              key={subItem.name}
              className={`${css.sunKind} ${
                selects.includes(subItem.name) ? css.active : ''
              }`}
              onClick={() => this.handleCheck(subItem)}
            >
              {subItem.name}
            </div>
          </div>
        ))}
      </div>
    )
  }
}

generally, it is best to encapsulate list items

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e4d3c5-44f2e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e4d3c5-44f2e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?