[react native] react-native-calendars 캘린더에 마킹하기
반응형

import { Calendar } from 'react-native-calendars';
export default () => {
const [markedDates, setMarkedDates] = React.useState(null);
const [dates, setDates] = React.useState(['2021-01-05', '2021-01-20']);
function addDates() {
let obj = dates.reduce(
(c, v) =>
Object.assign(c, {
[v]: { marked: true, dotColor: 'red' },
}),
{},
);
console.log(obj);
setMarkedDates(obj);
}
return (
<>
<View>
<Calendar
onDayPress={(day) =>{
addDates();
}}
markedDates={markedDates}
/>
</View>
</>
)
}

캘린더에 있는 날짜 아무거나 클릭 했을 때 addDates() 를 호출해서
2021-01-05 와 2021-01-20 날짜에
빨간색 마킹이 되도록 해봤다

저 dates state 만 관리해주면
유동적으로 바뀐다
더 자세한 사용법은
github.com/wix/react-native-calendars
wix/react-native-calendars
React Native Calendar Components 🗓️ 📆 . Contribute to wix/react-native-calendars development by creating an account on GitHub.
github.com
반응형
글이 도움이 되셨다면 공감과 광고 클릭 한번 부탁드립니다! 💕
감사합니다 ✨
댓글
이 글 공유하기
다른 글
-
[react native] textinput 입력 시 글자 유실 textinput lose focus react native
[react native] textinput 입력 시 글자 유실 textinput lose focus react native
2021.01.14 -
[react native] Invariant Violation: View config getter callback for component `firstView` must be a function (received `undefined`). Make sure to start component names with a capital letter.
[react native] Invariant Violation: View config getter callback for component `firstView` must be a function (received `undefined`). Make sure to start component names with a capital letter.
2021.01.08 -
[react native] Warning: Cannot update a component from inside the function body of a different component.
[react native] Warning: Cannot update a component from inside the function body of a different component.
2021.01.07 -
[react native] TypeError: this.setState is not a function.
[react native] TypeError: this.setState is not a function.
2020.12.31