question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to dynamically mark date

See original GitHub issue

Description

I have a Calender component, where I would like to mark a date which is the next day (nextDay).

export default class CustomCalender extends React.Component {
	render() {
		const today = moment().format("YYYY-MM-DD");
		const nextWeekDay = moment().add(7, 'days').format("YYYY-MM-DD");
		const nextDay = moment().add(1, 'days').format("YYYY-MM-DD");

		const mark = {
			'2017-08-16': {selected: true, marked: true}
		};

		return (
			<View style={styles.container}>
				<Text style={styles.labelText}>Select a date</Text>
				<Calendar
					minDate={today}
					maxDate={nextWeekDay}
					onDayPress={(day) => {
						console.log('selected day', day)
					}}
					
					markedDates={mark}
				/>
			</View>
		)
	}
}

Expected Behavior

How can I use the data of nextDay for the mark constant instead of ‘2017-08-16’?

Environment

"react": "16.0.0-alpha.12",
"react-native": "^0.47.0",
"react-native-calendars": "^1.5.8",

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:14 (1 by maintainers)

github_iconTop GitHub Comments

30reactions
overengineeredcommented, Aug 28, 2017

@robinlery use it like this:

	const mark = {
		[nextDay]: {selected: true, marked: true}
	};
22reactions
TimurAsayonokcommented, Aug 7, 2019

@sfm2222 @kinza88 This method doesn’t work because will get this wrong structure at the end you. You have to have structure like this:

    const mark = {
      '2018-06-05': { selected: true, marked: true },
      '2018-06-07': { selected: true, marked: true },
      '2018-06-18': { selected: true, marked: true }
    }

So, you have to work with your nextDay array and change this array to object correct structure. Example, try this (updated after @ekowcharles suggestions):

    const nextDays = [
      '2018-06-01',
      '2018-06-05',
      '2018-06-08',
      '2018-06-07',
      '2018-06-18',
      '2018-06-17',
      '2018-05-28',
      '2018-05-29'
    ];

    let newDaysObject = {};

    nextDays.forEach((day) => {
      newDaysObject[day] = {
          selected: true,
          marked: true
      };
    });

screen shot 2018-07-27 at 14 31 36

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to dynamically populate Calendar marked dates from api
Solution: const CalendarScreen = (props) => { const dispatch = useDispatch(); const access_token = useSelector((state) => state.auth.token); ...
Read more >
How to dynamically set marked dates from api in react-native ...
Coding example for the question How to dynamically set marked dates from api in react-native-calendar-strip?-React Native.
Read more >
mark multiple dates dynamically react native wix - iTecNote
I'm using react-native-calendars. This library provides ability to mark dates on the calendar once mark parameter is passed to calendar object.
Read more >
How to make a dynamic calendar in excel - YouTube
1) Use data validation to make drop down lists for the years and months. 2) Use the DATEVALUE and WEEKDAY formulas to make...
Read more >
React and Ionic Calendar Marked day classes Example
When you want to update the shape you can simply use CSS and override the styling: .mbsc-calendar-marks .mbsc-calendar-mark { // you custom override...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found