Comments (2)
간단히 말하면 setMenus
를 여러번 호출해서 생긴 문제입니다.
setMenus
를 호출하더라도 당장은 menus
의 값이 변하지 않습니다. (정확히는 update
함수에서 캡처한 menus
변수의 값이 불변입니다) menus
라는 변수가 담고 있는 값은 언제까지나 이전 렌더링에서 얻은 값입니다. 때문에 실제 setMenus
호출은 아래와 같이 이루어집니다.
setMenus(이전 리스트에서 1번 메뉴가 선택 해제된 리스트)
setMenus(이전 리스트에서 2번 메뉴가 선택 해제된 리스트)
setMenus(이전 리스트에서 3번 메뉴가 선택 해제된 리스트)
...
setMenus(이전 리스트에서 id번 메뉴가 선택된 리스트)
최종적으로는 가장 마지막에 호출한 setMenus
만 적용됩니다. 그러면 나머지 선택 해제된 값은 전부 무시되고 마지막에 메뉴가 추가로 선택된 리스트만 남게 됩니다.
해결 방법은 간단합니다. 모든 업데이트를 적용한 한 번의 setMenus
만 호출해주시면 됩니다. 이를테면 아래 코드처럼 짤 수 있습니다.
예시 코드
setMenus(menus
.map((m) => ({
...m,
isselected: m.id === menu.id ? "selected" : "none"
})));
from seminar-2022.
질문 올려주셔서 감사합니다. 다만 앞으로 코드는 복붙해서 ```codes```
로 감싸주시기 바랍니다.
from seminar-2022.
Related Issues (14)
- 질문 등록 방법
- 세미나 참여 기준과 관련하여 질문 드립니다. HOT 1
- Android Codelab 링크 관련 질문드립니다. HOT 2
- Storyboard 없이 SceneDelegate에 첫 시작 ViewController 세팅하는 방법
- React 세미나1 상세뷰 만들기 HOT 1
- React 세미나 1 가격 입력 시 쉼표 생성 관련 HOT 2
- Apple 공식 픽토그램 (SF Symbol) 사용법
- docker mysql 연결 문제 질문 HOT 2
- Kotlin으로 풀어보는 20.5기 코테 3번 문항에 대한 질문 HOT 1
- ArgumentResolver에서 request에 지정한 attribute 꺼내오기
- React 세미나2 로그인 안된 상태에서는 접근금지 HOT 6
- React 세미나2 url 변경 시 context 값이 초기화되는 현상에 관한 질문 HOT 2
- React 과제 2 공통 피드백
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from seminar-2022.