๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Frontend/React

[ ๋ฆฌ์•กํŠธ(React) ] console ์ฐฝ์— Warning: Using UNSAFE_componentWillMount in strict mode is not recommended and may indicate bugs in your code ๋œฐ ๋•Œ

by YWTechIT 2021. 6. 16.
728x90

๐Ÿ“ console ์ฐฝ์—์„œ Warning: Using UNSAFE_componentWillMount in strict mode is not recommended and may indicate bugs in your code ๋œฐ ๋•Œ

๋ณ‘๊ณผ ํ…Œ์ŠคํŠธ ํ”„๋กœ์ ํŠธ๋ฅผ ์ž˜ ์ง„ํ–‰ํ•˜๊ณ  ์žˆ๋‹ค๊ฐ€ ๊ฐ‘์ž๊ธฐ console ์ฐฝ์— Warning์ด ๋–ด๋‹ค.

 

 

๊ตฌ๊ธ€๋ง์„ ํ•ด๋ณด๋‹ˆ๊นŒ nfl/react-helmet#548, nfl/react-helmet#623 ์— ๋น„์Šทํ•œ ๊ธ€์ด ์žˆ์—ˆ๋Š”๋ฐ ์›์ธ์€ strict mode์—์„œ UNSAFE_componentWillMount๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์€ ๊ถŒ์žฅํ•˜์ง€ ์•Š๊ณ  ๊ฐ€๋” ๋ฒ„๊ทธ๋ฅผ ์ผ์œผํ‚ฌ ์ˆ˜ ์žˆ๋‹ค๋Š” ๋‚ด์šฉ์ด์—ˆ๋‹ค.

 

ํ•ด๊ฒฐ๋ฐฉ๋ฒ•์„ ์ฐพ์•„๋ณด๋‹ˆ ๋ณดํ†ต React-helmet ๋ฒ„์ „์ด ^6.0.0 ์ดํ•˜์—์„œ ๋งŽ์ด ๋ฐœ์ƒํ•œ๋‹ค๋Š” ๋‚ด์šฉ์ด ๋Œ€๋‹ค์ˆ˜์˜€๋‹ค. ํ•˜์ง€๋งŒ ๋‚ด๊ฐ€ ์„ค์น˜ํ•œ React-helmet ๋ฒ„์ „์€ ^6.1.0์ด์—ˆ๊ณ , ๋ฒ„์ „์ด ๋‚ฎ์•„์„œ ๋ฐœ์ƒํ•œ ๊ฒƒ ๊ฐ™์ง„ ์•Š์•„ ๋ณด์˜€๋‹ค. (ํ˜น์‹œ ๋ฒ„์ „์ด ^6.0.0์ดํ•˜๋ผ๋ฉด, ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์—…๋ฐ์ดํŠธ๋ฅผ ํ•˜๊ณ  ๋‚˜์„œ import ํ•  ๋•Œ import { Helmet } from "react-helmet"๋กœ ์ž‘์„ฑํ•ด๋ณด์ž.)

 

๋‹ค๋ฅธ ๊ธ€ ์ค‘์— react-helmet-async๋ฅผ ์‚ฌ์šฉํ•ด๋ณด๋ผ๋Š” ๊ธ€์ด ์žˆ์–ด์„œ ํ•ด๋‹น ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ๋‹ค์šด๋กœ๋“œํ•˜๊ณ  ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ž‘์„ฑํ–ˆ๋”๋‹ˆ ๋” ์ด์ƒ warning ์ฐฝ์ด ๋œจ์ง€ ์•Š์•˜๋‹ค. ๊นƒํ—ˆ๋ธŒ์—์„œ react-helmet-async ํŒจํ‚ค์ง€์— ๋“ค์–ด๊ฐ€๋ณด๋‹ˆ๊นŒ Helmet๊ณผ ์‚ฌ์šฉ๋ฒ•์€ ๋™์ผํ•˜๊ณ  ์Šค๋ ˆ๋“œ๊ฐ€ ์•ˆ์ „ํ•˜์ง€ ์•Š์€ react-side-effect์— ์˜์กดํ•œ๋‹ค๊ณ  ๋‚˜์™€์žˆ๋‹ค.

 

ํ•ด๋‹น ํŒจํ‚ค์ง€๋Š” ์„œ๋ฒ„์—์„œ ๋น„๋™๊ธฐ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•  ๊ฒฝ์šฐ ๋ฐ์ดํ„ฐ ์š”์ฒญ ๋ณ„๋กœ Helmet์„ ์บก์Šํ™” ํ•˜๊ธฐ์œ„ํ•ด ์‚ฌ์šฉํ•˜๋Š” ํŒจํ‚ค์ง€๋ผ๊ณ  ๋‚˜์™€์žˆ๋‹ค. ๊ทธ๋ƒฅ Helmet์„ ์บก์Šํ™” ํ•ด์ค€๋‹ค๊ณ  ์ƒ๊ฐํ•˜๋ฉด ํŽธํ•˜๋‹ค. ์‚ฌ์šฉ๋ฒ•์€ ๋‹ค์Œ ์ฝ”๋“œ์ฒ˜๋Ÿผ ์‚ฌ์šฉํ•˜์ž.

 

import { Helmet, HelmetProvider } from "react-helmet-async";

const Landing = () => {
  return (
    <>
      <HelmetProvider>
        <Helmet>
          {/* contents... */}
        </Helmet>
      </HelmetProvider>
    </>
  )
}

export default Landing;
์ดํ›„ console.log์ฐฝ์— ๋” ์ด์ƒ Warning์ด ๋œจ์ง€ ์•Š์•˜๋‹ค.
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€