1. [React] 여러 개의 checkbox 관리하는 법

    import React, { useState, useEffect } from "react";
    
    export default function App(){
      const [checkedInputs, setCheckedInputs] = useState([]);
    
      const changeHandler = (checked, id) => {
        if (checked) {
          setCheckedInputs([...checkedInputs, id]);
        } else {
          // 체크 해제
          setCheckedInputs(checkedInputs.filter((el) => el !== id));
        }
      };
    
    
      return (
        <div>
          <input 
            id={???}
            type="checkbox" 
            onChange={()=>{
              changeHandler(e.currentTarget.checked, id값)
            }}
            checked={checkedInputs.includes(id값 …
    read more

links

social