알림이 1초마다 두 개씩 뜹니다.
분명히 코드를 그대로 따라 쳤는데 1초에 두 번씩 알림이 나오는 경우도 존재하나요?
Warning: Each child in a list should have a unique "key" prop. 오류도 떴습니다.
각각 notification.jsx, notificationList.jsx 코드입니다
import React from "react"
const styles = {
wrapper: {
margin: 8,
padding: 8,
display: 'flex',
flexDirection: 'row',
border: '1px solid grey',
borderRadius: 16
},
messageText: {
color: 'black',
fontSize: 16
}
}
class Notification extends React.Component {
constructor(props) {
super(props)
this.state = {}
}
render() {
return (
<div style={styles.wrapper}>
<span style={styles.messageText}>{this.props.message}</span>
</div>
)
}
}
export default Notificationimport React from 'react'
import Notification from './notification'
const reservedNotifications = [
{
message: '안녕하세요, 오늘 일정을 알려드립니다.'
},
{
message: '점심식사 시간입니다.'
},
{
message: '이제 곧 미팅이 시작됩니다.'
},
{
message: '안녕하세요, 오늘 일정을 알려드립니다.'
},
{
message: '점심식사 시간입니다.'
},
{
message: '이제 곧 미팅이 시작됩니다.'
},
{
message: '안녕하세요, 오늘 일정을 알려드립니다.'
},
{
message: '점심식사 시간입니다.'
},
{
message: '이제 곧 미팅이 시작됩니다.'
},
{
message: '안녕하세요, 오늘 일정을 알려드립니다.'
},
{
message: '점심식사 시간입니다.'
},
{
message: '이제 곧 미팅이 시작됩니다.'
},
]
var timer
class NotificationList extends React.Component {
constructor(props) {
super(props)
this.state = {
notifications: []
}
}
componentDidMount() {
const { notifications } = this.state
timer = setInterval(() => {
if(notifications.length < reservedNotifications.length) {
const index = notifications.length
notifications.push(reservedNotifications[index])
this.setState({
notifications: notifications
})
} else {
clearInterval(timer)
}
}, 1000)
}
render() {
return (
<div>
{this.state.notifications.map(v => {
return <Notification message={v.message}/>
})}
</div>
)
}
}
export default NotificationList
답변 1
4
안녕하세요, 소플입니다.
해당 문제는 리액트 버전18에서 Strict Mode의 동작이 변경되었기 때문입니다.
아래 답변을 확인해보시면 도움이 되실 겁니다😀
https://www.inflearn.com/questions/619705/comment/205023
감사합니다.
강의가 삭제되었다고 합니다
0
109
1
이거 왜 존재하지 않는다고 뜨는건가요
0
136
1
존재하지 않는 수업이라고 떠요
0
184
1
안드로이드 에뮬레이터 오류
0
100
1
교재 구입해서 강의 들으려고 하는데 커리큘럼이 없어졌어요.
0
129
1
prevIsConfiromed 질문
1
144
2
chapter14 잘이해가 되지않습니다..
1
136
2
2025년 3월 리액트버전
1
204
2
npm 설치 오류
1
178
1
chapter_07 콘솔로그 질문드려요~!
1
128
2
안녕하세요 미니블로그 실습 질문드립니다.
1
179
3
에러가 떠요
1
219
3
Chapter6 질문 드립니다
1
210
2
실습 코드 있을까요?
1
208
2
상태가 업데이트될때 컴포넌트 최상단의 console.log 코드가 두번 실행되는 이유가 궁금합니다.
1
234
2
npx create-react-app my-app 명령어 입력이 잘못된 것 같습니다
0
309
3
이름과 코멘트 줄바꿈이 안 됩니다.
0
142
1
버튼이 안 뜹니다
0
305
2
npx create-react-app my-app
1
471
2
jsx 코드 작성해보기에서 index.js 수정 후 에러 뜹니다.
1
377
3
Chapter_05 터미널, 리액트 에러
0
194
2
npx create-react-app my-app 명령어 반응없음
1
433
3
import 코드 에러
1
215
1
백틱
1
122
1





