ReactTags
์ฌ์ฉํ์ฌ ๊ฒฝ๊ณ ๊ฐ ํ์๋ฉ๋๋ค.
Warning: Failed prop type: You provided a `value` prop to a form field without an `onChange` handler. This will render a read-only field. If the field should be mutable use `defaultValue`. Otherwise, set either `onChange` or `readOnly`.
in input (created by Input)
in div (created by Input)
in Input (created by ReactTags)
in div (created by ReactTags)
in div (created by ReactTags)
์ฌ๊ธฐ ์ ์ธ๊ธ๋ ๋ด์ฉ https://github.com/i-like-robots/react-tags/blob/master/lib/Input.js#L78 ์ ๋ค์๊ณผ ๊ฐ์ด ๋ณ๊ฒฝํด์ผ ํฉ๋๋ค.
defaultValue={query}
์ด๋ป๊ฒ ์๊ฐํ๋์?
๊ฐ์ฌ ํด์!
๋์ผํ ๋ฌธ์ ๊ฐ ์์ต๋๋ค. ์ ์ ์ฌํญ์ด ์์ต๋๊น?
๋๋ ์ด๊ฒ์ ์ง์ ๋ณด์ง ๋ชปํด์ ๋๋ ต์ต๋๋ค. ์ด๋ค React ๋ฒ์ ์ ์ฌ์ฉํ๊ณ ์๋์ง ์๋ ค์ฃผ์ค ์ ์์ต๋๊น?
๋๋ React 16.3.2๋ฅผ ์ฌ์ฉํ๊ณ ์์ต๋๋ค
@i-like-robots ์ ๋ ์ด ๋ฌธ์ ๋ฅผ ๊ฒช๊ณ ์์ต๋๋ค.
defaultValue๋ก ๋ณ๊ฒฝํ๊ธฐ ์ํด PR์ ์ถ๊ฐํ์ง๋ง ์ด ๋ฌธ์ ๊ฐ ํด๊ฒฐ๋ ๋๊น์ง ๊ฒฝ๊ณ ๋ฅผ ํผํ๋ ํดํน์ ์ํ๋ฉด ReactTags๋ฅผ ์ฌ์ฉํ๋ ํด๋์ค์ noop ๋ฉ์๋๋ฅผ ์ถ๊ฐํ๊ณ ์ด๋ฅผ ๊ตฌ์ฑ ์์์ onChange๋ก ์ฐธ์กฐํ ์ ์์ต๋๋ค. ๋ณด๊ธฐ ํํ์ง๋ง ๊ฒฝ๊ณ ๋ฅผ ์ค์งํฉ๋๋ค.
noOp() {
// does nothing
}
<ReactTags
tags={this.state.tags}
suggestions={this.state.suggestions}
handleAddition={this.handleTagAddition}
handleDelete={this.handleTagDelete}
inputAttributes={{ onChange: this.noOp }}
/>
์ด๊ฒ์ ํฅ๋ฏธ๋ก์ด ๋ฌธ์ ์ ๋๋ค. ๋ช ๋ ์ https://github.com/facebook/react/issues/1118 ์์ ๊ธธ๊ฒ ๋ ผ์๋์์ต๋๋ค(16.3.2๋ฅผ ํฌํจํ ๋ชจ๋ ๋ฒ์ ์ React์์ ์ด ๊ฒฝ๊ณ ๋ฅผ ๋ณธ ์ ์ด ์์ง๋ง! )
ํ์ฌ ๊ตฌํ์ ๊ธฐ์ ์ ์ผ๋ก _์๋ชป๋_ ๊ฒ์ ์์ง๋ง ์ฝ์์ ์ด์ง๋ฝํ๋ ๊ฒฝ๊ณ ๋ ์ง์ฆ๋๊ณ ํผํด์ผ ํ๋ค๋ ๋ฐ ๋์ํฉ๋๋ค.
defaultValue
์ค์ ์ด ์๋ํ์ง ์์ ๊ฒฐ๊ณผ๋ฅผ ์ด๋ํ ์ ์์ผ๋ฏ๋ก ์ฌ๋ฐ๋ฅธ ์๋ฃจ์
์ธ์ง ํ์ ํ ์ ์์ต๋๋ค(https://github.com/i-like-robots/react-tags/pull/139#issuecomment-431006214 ์ฐธ์กฐ). ) ๊ทธ๋ฌ๋ ์ ์ฌ์ ์ผ๋ก ๋ช ๊ฐ์ง ๋ค๋ฅธ ํด๊ฒฐ ๋ฐฉ๋ฒ์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
์ด๊ฒ์ ์ข ๋ ์ดํด๋ณด๋ฉด ์ด ๊ฒฝ๊ณ ์๋ 5๊ฐ์ง ์กฐ๊ฑด์ด ์์์ ์ ์ ์์ต๋๋ค.
๊ทธ๊ฒ์ ๊ธฐ๋ณธ์ ์ผ๋ก์ด _should_๊ฐ ํ๊ฐ ๋๋ฌธ์ ์ด์ต ๋๋ฅผ ์ฒซ ๋ฒ์งธ ์กฐ๊ฑด์
๋๋ค true
์ ๋ํ ๊ธฐ๋ณธ ๊ฐ ๋๋ฌธ์ state.query
๋น ๋ฌธ์์ด์
๋๋ค. ๋ฐ๋ผ์ ํจ์๊ฐ ์กฐ๊ธฐ์ ๋ฐํ๋๊ณ ๊ฒฝ๊ณ ๋ฅผ ์ถ๋ ฅํ์ง ์์์ผ ํฉ๋๋ค.
๋ฐ๋ผ์ ์ด ๊ฒฝ๊ณ ๋ฅผ ํธ๋ฆฌ๊ฑฐํ๋ ค๋ฉด ๊ธฐ๋ณธ ์ํ(https://github.com/i-like-robots/react-tags/blob/master/lib/ReactTags.js#L35)๋ฅผ ๋ณ๊ฒฝํ์ฌ ์ง์คํ ๊ฐ์ผ๋ก ๋ง๋ค์ด์ผ ํ์ต๋๋ค.
๊ฒฝํํ ์ฌ๋ ์ค ์ ๊ฐ ๋ ์์ธํ ๋ณผ ์ ์๋๋ก ๋ฌธ์ ๋ฅผ ๋ณด์ฌ์ฃผ๋ ์๊ฐ ์์ต๋๊น?
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
defaultValue๋ก ๋ณ๊ฒฝํ๊ธฐ ์ํด PR์ ์ถ๊ฐํ์ง๋ง ์ด ๋ฌธ์ ๊ฐ ํด๊ฒฐ๋ ๋๊น์ง ๊ฒฝ๊ณ ๋ฅผ ํผํ๋ ํดํน์ ์ํ๋ฉด ReactTags๋ฅผ ์ฌ์ฉํ๋ ํด๋์ค์ noop ๋ฉ์๋๋ฅผ ์ถ๊ฐํ๊ณ ์ด๋ฅผ ๊ตฌ์ฑ ์์์ onChange๋ก ์ฐธ์กฐํ ์ ์์ต๋๋ค. ๋ณด๊ธฐ ํํ์ง๋ง ๊ฒฝ๊ณ ๋ฅผ ์ค์งํฉ๋๋ค.