티스토리 뷰
Define Styled Components outside of the render method
It is important to define your styled components outside of the render method, otherwise it will be recreated on every single render pass. Defining a styled component within the render method will thwart caching and drastically slow down rendering speed, and should be avoided.
Write your styled components the recommended way:
const StyledWrapper = styled.div`
/* ... */
`
const Wrapper = ({ message }) => {
return <StyledWrapper>{message}</StyledWrapper>
}
Instread of...
const Wrapper = ({ message }) => {
// WARNING: THIS IS VERY VERY BAD AND SLOW, DO NOT DO THIS!!!
const StyledWrapper = styled.div`
/* ... */
`
return <StyledWrapper>{message}</StyledWrapper>
}
'토막지식시리즈 > React 토막지식' 카테고리의 다른 글
리액트에서 "렌더링(rendering)"이란? (1) | 2024.08.23 |
---|---|
react-query에서 특정 상황에서만 데이터를 조회하고 싶을 때 (0) | 2022.12.10 |
SWR API Options (feat. 라이브러리에 대한 고찰) (0) | 2021.06.30 |
React Fragments (0) | 2021.06.25 |
댓글
최근에 올라온 글
최근에 달린 댓글
TAG
- 20200624
- 20200317
- 20200424
- 20200406
- 20200425
- 20200330
- 20200417
- chapter7
- 20200502
- likelion
- 20200504
- 20201204
- 20200427
- 20200423
- 20200413
- 20200415
- 20200319
- 생활코딩리눅스
- 20200428
- 20200622
- 20200420
- 20200403
- 20200510
- 20200503
- 백준
- 20200804
- chapter8
- 20200429
- 20200512
- 20200421
- Total
- Today
- Yesterday