avatar
Published on

리액트 useState 훅 사용하기

Authors
  • avatar
    Name
    Haneul
    Twitter

배열 state 

1. 추가

const [language, setLanguage] = useState([]);

setLanguage([...language, newLanguage]);
// or

setLanguage(language.concat(newLanguage));

2. 삭제

const [language, setLanguage] = useState([]);

setLanguage(language.filter(item => item.id !== id));

3. 수정

const [language, setLanguage] = useState([]);

setLanguage(
      language.map(item =>
        item.id === id ? { ...item, active: !item.active } : item
      )
    );