์ด ์ข๊ฒ๋ ์ ๋ ๋ฉฐ์น ์ ์ ์ด๊ฒ์ ํ์ต๋๋ค ๐: https://github.com/i-like-robots/react-tags/compare/v5.13.0...async-fetch-example
์ผ!, ์ด๊ฒ๋ง ์ฐพ๊ณ ์์ด!
axios ๋ฐ ํํฌ์ ์:
//initial api call
const [{ data: labelsData }, doGetLabels] = useAxios({
url: '/labels',
})
const [suggestions, setSuggestions] = useState([])
const [busy, setBusy] = useState(false)
const handleInputChange = debounce((name) => {
if (!busy) {
setBusy(true)
doGetLabels({ params: { name } })
}
})
//getResponseData is my custom parser for the BE response
useEffect(() => {
const labels = labelsData ? getResponseData(labelsData).labels : []
if (setBusy) {
setBusy(false)
}
setSuggestions(labels)
}, [labelsData])
๋๋จธ์ง ์ฝ๋๋ @i-like-robots PR๊ณผ ๋์ผํ๊ฒ ์ ์ง๋ฉ๋๋ค.
์๋ฅผ ๋ค์ด ์ฃผ์
์ ๊ฐ์ฌํฉ๋๋ค. @i-like-robots์ ์์ ๋ฌธ์ ๊ฐ ์๋ ๊ฒ ๊ฐ์ต๋๋ค.
์ต์
๋ชฉ๋ก์ onInput
์ปค์คํ
ํธ๋ค๋ฌ https://github.com/i-like-robots/react-tags/blob/6.0/lib/ReactTags.js#L130 ๋ฐ๋ก ๋ค์์ ์
๋ฐ์ดํธ๋ฉ๋๋ค
๊ทธ๋ฌ๋ onInput
ํธ๋ค๋ฌ ๋ด๋ถ์์ ์๋ฒ๋ฅผ ์ฟผ๋ฆฌํ๋ฉด ์๊ฐ์ด ๊ฑธ๋ฆฝ๋๋ค.
๊ฒฐ๊ณผ์ ์ผ๋ก ์ต์
๋ชฉ๋ก์๋ ํญ์ ์ต๊ทผ ํธ์ถ์ด ์๋ ์ด์ ํธ์ถ์ ์ ์ ๋ชฉ๋ก์ด ํฌํจ๋ฉ๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
์ด ์ข๊ฒ๋ ์ ๋ ๋ฉฐ์น ์ ์ ์ด๊ฒ์ ํ์ต๋๋ค ๐: https://github.com/i-like-robots/react-tags/compare/v5.13.0...async-fetch-example