조건부 렌더링
조건 별 처리
function conditionalRendering(content, isStrong = false) {
if (isStrong) {
return <strong>{content}</strong>
} else {
return <p>{content}</p>
}
}
// <p>조건부 렌더링</p>
const normalMessage = conditionalRendering('조건부 렌더링')
// <strong>조건부 렌더링</strong>
const strongMessage = conditionalRendering('조건부 렌더링', true)const switchRendering = (emotion) => {
switch (emotion) {
default:
case '좋아요':
return getEmotionFace('good.jpg', emotion)
case '훈훈해요':
return getEmotionFace('so-good.jpg', emotion)
case '슬퍼요':
return getEmotionFace('sad.jpg', emotion)
case '화나요':
return getEmotionFace('angry.jpg', emotion)
case '후속기사원해요':
return getEmotionFace('want.jpg', emotion)
}
}
switchRendering('후속기사원해요')라이브 예제
인라인 조건 처리
Last updated