[React] input state () - 단위변환기1 Warning : Invalid DOM property

2026. 2. 2. 12:52·Frontend/React
니콜라스 쌤의 노마드코더 'ReactJS로 영화 웹 서비스 만들기' 보면서 공부한 내용입니다.
부족한 내용이나 잘못된 내용은 댓글남겨주시면 감사하겠습니다!

출처 : https://nomadcoders.co/react-for-beginners

 

 

이전글에 이어,

[React] State Functions (state 값 설정 방법 2가지)

이번에는 JSX문법을 통해 단위변환기를 만들어보겠습니다.

 

우선 분-> 시간으로 바꾸기 위해 필요한 요소들만 먼저 추가해보았습니다.

<!DOCTYPE html>
<html>
    <body>
        <div id="root"></div>
    </body>
    <!--React js, DOM install-->
    <script src="https://unpkg.com/react@17.0.2/umd/react.production.min.js"></script>
    <script src="https://unpkg.com/react-dom@17.0.2/umd/react-dom.production.min.js"></script>
    <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
    <script type="text/babel">
        function App () {
            return (
                <div>
                    <h1>Super Converter</h1>
                    <label for="minutes">Minutes</label>
                    <input id="minutes" placeholder="Minutes" type="number"/>
                    <label for="hours">Hours</label>
                    <input id="hours" placeholder="Hours" type="number"/>
                </div>
            );
        }
        const root = document.getElementById("root");
        ReactDOM.render(<App/>, root);
        
    </script>
</html>

 

문제 없이 이쁘게 잘 나온 것을 볼 수 있는데요, 사실 JSX문법 상 틀린 문법이 있습니다.

 

그 문법이 어떤 거인지 확인 하기 위해 react를 install하는 부분을 조금 수정해보겠습니다.

production -> development로 변경을 하면

<script src="https://unpkg.com/react@17.0.2/umd/react.production.min.js"></script>
<script src="https://unpkg.com/react-dom@17.0.2/umd/react-dom.production.min.js"></script>


<script src="https://unpkg.com/react@17.0.2/umd/react.development.js"></script> 
<script src="https://unpkg.com/react-dom@17.0.2/umd/react-dom.development.js"></script>

 

다음처럼 오류를 볼 수 있습니다. 현재 html 태그 문법을 jsx를 통해 적었는데 for나 class는 javaScript용어이기 때문에 오류가 발생하게 됩니다.

 

1. Warning : Invalid DOM property 

 

그래서 jsx를 사용할 때는 사실상 html 문법을 아예 그대로 쓰기보다는 일부를 수정해줘야하는 점이 중요합니다.

class는 className으로, for는 htmlFor로 써줘야합니다.

 

2. input state

<!DOCTYPE html>
<html>
    <body>
        <div id="root"></div>
    </body>
    <!--React js, DOM install-->
    <script src="https://unpkg.com/react@17.0.2/umd/react.development.js"></script> 
    <script src="https://unpkg.com/react-dom@17.0.2/umd/react-dom.development.js"></script>
    <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script> 
    <script type="text/babel">
        // 단위 변환기
        // 시간 : 분 -> 시간
        function App () {
            const [minutes, setMinutes] = React.useState("");
            const onChange = (event) => {
                setMinutes(event.target.value);
            }
            const [hours, setHours] = React.useState("");
            return (
                <div>
                    <h1 className="hi">Super Converter</h1>
                    <label htmlFor="minutes">Minutes</label>
                    <input 
                        value={minutes} 
                        id="minutes" 
                        placeholder="Minutes" 
                        type="number"
                        onChange={onChange}
                    />
                    <h4>You want to convert {minutes}</h4>
                    <label htmlFor="hours">Hours</label>
                    <input id="hours" placeholder="Hours" type="number"/>
                </div>
            );
        }
        const root = document.getElementById("root");
        ReactDOM.render(<App/>, root);
    </script>
</html>

 

onChange에서 event를 확인해보면 target안에 우리가 원하는 value값이 들어가 있어서 minutes 변화 함수에 해당 값을 전달해주면 됩니다!

 

 

다음 글에서는 단위변환기를 완성해보겠습니다.

[React] 분 <-> 시, 리셋기능 - 단위변환기2

 

읽어주셔서 감사합니다.

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

[React] Divide : 작은 컴포넌트로 분할 - 단위변환기 3  (0) 2026.02.07
[React] 분 <-> 시, 리셋기능 - 단위변환기2  (0) 2026.02.03
[React] State Functions (state 값 설정 방법 2가지)  (0) 2026.02.02
[React] 컴포넌트 state (React.useState(), setState)  (0) 2026.01.30
[React] JSX문법 기초 (JS to JSX)  (0) 2026.01.30
'Frontend/React' 카테고리의 다른 글
  • [React] Divide : 작은 컴포넌트로 분할 - 단위변환기 3
  • [React] 분 <-> 시, 리셋기능 - 단위변환기2
  • [React] State Functions (state 값 설정 방법 2가지)
  • [React] 컴포넌트 state (React.useState(), setState)
min_sol
min_sol
  • min_sol
    비글개발연구소🐾
    min_sol
  • 전체
    오늘
    어제
    • 분류 전체보기 (278)
      • Programming (128)
        • Algorithm (52)
        • JAVA (40)
        • GIS (5)
        • PyQt (10)
        • C# (11)
        • Mobile (6)
        • AI (4)
      • Backend (36)
        • Spring (14)
        • JSP (11)
        • Network (5)
      • Frontend (29)
        • React (11)
        • Vue (13)
        • Next.js (4)
      • Database (10)
        • PostgreSQL (1)
        • Oracle (8)
        • Elasticsearch (1)
      • DevOps (8)
        • Linux (7)
        • Mac (1)
      • Tools (31)
        • IntelliJ (1)
        • GitHub (10)
        • RPA (20)
      • Security (9)
      • etc (21)
        • ERROR (5)
        • 세미나 | 교육 (10)
        • 자격증 (1)
        • 일상 (2)
        • 2021 (2)
  • 인기 글

  • 태그

    알고리즘
    PyQt5
    vue.js
    스윙
    VUE
    이클립스
    연습문제
    jsp
    자동화
    백준
    생능출판
    계산기
    Java
    코딩테스트
    RPA
    자료구조
    자바
    PyQt
    spring
    명품자바에센셜
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
min_sol
[React] input state () - 단위변환기1 Warning : Invalid DOM property
상단으로

티스토리툴바