Frontend/React

React + styledComponent + radioButton / not updating

섕걍 2022. 4. 19. 14:02

아~ 진짜~~~
이게 뭐라구 이렇게 고생을 했나
싶고ㅋㅋㅋㅋㅋ

styled Component로 만든 radio Button이 checked된게 Update되지 않았다!
value를 콘솔에 찍어보면 분명히 잘 set되는데!
ㅋㅋㅋㅋㅋㅋ

이게 머라고 어제 저녁부터...^^..ㅋ
문제는...바로바로바로

e.preventDefatul(); 때문이였다^^ㅋ

이거 지워주니까 허무하게 잘 됨요ㅎㅎ;;;

  const onChangeName = (e: React.ChangeEvent<HTMLInputElement>) => {
    // e.preventDefault();
    const {
      target: { value },
    } = e;
    setBottleName(value);
  };

  const onChangeShape = (e: React.ChangeEvent<HTMLInputElement>) => {
    // e.preventDefault();
    const {
      target: { value },
    } = e;
    setBottleShape(value);
  };

주석처리 해주니까 잘 되는군여

e.preventDefault()

너 뭐 야

참고
https://stackoverflow.com/questions/43430013/react-radio-button-not-update-selection

React radio button not update selection

Trying React radio but the strange thing is that the radio selection will not update its view. Can anyone take a look at the code below and let me know what's wrong? class Test extends React.Com...

stackoverflow.com

'Frontend > React' 카테고리의 다른 글

forwardRef 사용법  (0) 2022.05.26
forwardRef 를 알아보자  (0) 2022.05.24
Manifest: Line: 1, column: 1, Syntax error.  (0) 2022.04.06
React 18에서 지원하지 않는 [ReactDOM.render]  (0) 2022.04.06
18. React - Redux  (0) 2021.01.06