๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Lect & Tip/javascript, jQuery

ReactJS input, select disabled ์ œ์–ด. Warning: Received the string `false` for the boolean attribute `disabled`. The browser will interpret it as a truthy value. Did you mean disabled={false}?

by ๋‚ฏ์„ ๊ณต๊ฐ„2019 2021. 3. 23.
๋ฐ˜์‘ํ˜•

ReactJS Warning: Received the string `false` for the boolean attribute `disabled`. The browser will interpret it as a truthy value. Did you mean disabled={false}?

ReactJS input, select disabled ์ œ์–ด. 

index.js:1 Warning: Received the string `false` for the boolean attribute `disabled`. The browser will interpret it as a truthy value. Did you mean disabled={false}?
    at input
    at td
    at tr
    at tbody
    at table
    at div
    at CompanyInfo (http://localhost:3000/static/js/main.chunk.js:2621:3)
    at CompanyInfoContainer
    at Route (http://localhost:3000/static/js/vendors~main.chunk.js:63206:29)
    at Switch (http://localhost:3000/static/js/vendors~main.chunk.js:63408:29)
    at div
    at div
    at div
    at CompanyManageLayout (http://localhost:3000/static/js/main.chunk.js:5053:3)
    at Route (http://localhost:3000/static/js/vendors~main.chunk.js:63206:29)
    at Switch (http://localhost:3000/static/js/vendors~main.chunk.js:63408:29)
    at Router (http://localhost:3000/static/js/vendors~main.chunk.js:62841:30)
    at ConnectedRouter (http://localhost:3000/static/js/vendors~main.chunk.js:2566:7)
    at ConnectedRouterWithContext (http://localhost:3000/static/js/vendors~main.chunk.js:2689:25)
    at ConnectFunction (http://localhost:3000/static/js/vendors~main.chunk.js:60203:75)
    at App (http://localhost:3000/static/js/main.chunk.js:312:3)
    at Provider (http://localhost:3000/static/js/vendors~main.chunk.js:59916:20)

๋ฆฌ์•กํŠธ๋กœ ํผ์ด ๋“ค์–ด๊ฐ„ ํŽ˜์ด์ง€๋ฅผ ์ž‘์„ฑํ•˜๋˜ ์ค‘์— ์ด๋Ÿฐ ์˜ค๋ฅ˜๊ฐ€ ๋–ด๋‹ค.

ํ•„์ž๊ฐ€ ๋งŒ๋“ค๋˜ ํŽ˜์ด์ง€๋Š” ์ƒํƒœ ๊ฐ’์— ๋”ฐ๋ผ์„œ 'viewDetail'์ผ ๋•Œ๋Š” ์ƒ์„ธํ™”๋ฉด์ธ ๊ฒƒ์ฒ˜๋Ÿผ ๋ณด์—ฌ์ฃผ๋‹ค๊ฐ€ "์ˆ˜์ •" ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด 'viewEdit'๋ชจ๋“œ๊ฐ€ ๋˜๋Š” ํŽ˜์ด์ง€๋‹ค.

<input type="text" id="addr" disabled={modeDisabled} value={companyInfo.addr} ref={inpAddr}/>

์ƒ์„ธํ™”๋ฉด์œผ๋กœ ๋ณด์—ฌ์ค„ ๋•Œ disabled๊ฐ€ true๊ฐ€ ๋˜์–ด์•ผ ํ•ด์„œ 

  const [modeDisabled, setModeDisabled] = useState("false");

์ด๋ ‡๊ฒŒ ์ž‘์„ฑํ–ˆ๋”๋‹ˆ ๋ฐœ์ƒ๋œ ์˜ค๋ฅ˜๋‹ค.

์ œ๋Œ€๋กœ ์‚ฌ์šฉํ•˜๋ ค๋ฉด "false"๊ฐ€ ์•„๋‹ˆ๋ผ false๋ฅผ ์จ์ค˜์•ผ ํ•œ๋‹ค.

  const [modeDisabled, setModeDisabled] = useState(false);

์ด๋ ‡๊ฒŒ ์ œ๋Œ€๋กœ ์‚ฌ์šฉํ•˜๋ฉด select๊ฐ€ ๋ฐ›์•„๋“ค์ด์ง€ ๋ชปํ•œ๋‹ค.

์ด๋Ÿด ๋•Œ

  const [modeDisabled, setModeDisabled] = useState(false);
  
 ...
 
 setModeDisabled(true);

useState๋ฅผ ์ด๋ ‡๊ฒŒ ํ™œ์šฉํ•œ๋‹ค.

์ค‘์š”ํ•œ ์ ์€ modeDisabled๊ฐ€ true์ผ ๋•Œ disabled ํ•˜๊ฒ ๋‹ค๋Š” ๋œป์ด๋ผ๋Š” ๊ฒƒ์„ ๊ธฐ์–ตํ•ด์•ผ ํ•œ๋‹ค.

{ ...( modeDisabled && { disabled: true } ) }

๊ฐ ํผ ์š”์†Œ์—์„œ๋Š” ์ด๋ ‡๊ฒŒ ์‚ฌ์šฉํ•ด ์ค€๋‹ค.

modeDisabled===true ์ธ ์ƒํƒœ๊ฐ’์„ ๊ฐ€์งˆ ๋•Œ๋งŒ disabled:true๊ฐ€ ์ ์šฉ๋œ๋‹ค.

<input disabled />๊ฐ€ ์ ์šฉ๋œ ์ƒํƒœ style๋กœ border๋ฅผ ์—†์• ๊ณ  disabled์ฒ˜๋ฆฌ๋˜์–ด์„œ ์ผ๋ฐ˜ ํ…์ŠคํŠธ์ฒ˜๋Ÿผ ๋ณด์ธ๋‹ค.

modeDsiabled===false๊ฐ’์ผ ๋•Œ๋Š” disabled๋Š” ์ ์šฉ๋˜์ง€ ์•Š๋Š”๋‹ค.

ํผ์š”์†Œ์— disabled attribute๊ฐ€ ์ ์šฉ๋˜์ง€ ์•Š์€ ์ƒํƒœ. border๊ฐ’์„ ์‚ด๋ ค๋†จ๊ณ , disabled๊ฐ€ ์ ์šฉ๋˜์ง€ ์•Š์•„์„œ ์ž…๋ ฅ๊ณผ ์ˆ˜์ •์ด ๊ฐ€๋Šฅํ•œ ์ƒํƒœ๋‹ค.

ํ•œ ํŽ˜์ด์ง€์—์„œ ์ƒ์„ธ๋ณด๊ธฐ์™€ ์ˆ˜์ •์„ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์ด ์žฅ์ ์ด๋‹ค.

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€