Skip to content

Instantly share code, notes, and snippets.

@rockymeza
Created April 9, 2018 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rockymeza/503c4b2343982bbaf88753b2369a99d8 to your computer and use it in GitHub Desktop.
Save rockymeza/503c4b2343982bbaf88753b2369a99d8 to your computer and use it in GitHub Desktop.
Pure implementation of WeekendStatus
import * as React from 'react';
const WeekendStatus = ({ currentTime }) => {
// Because we take currentTime as a prop, we now no longer depend
// on the external system time in our render function. We are now
// a pure function
const dayOfWeek = new Date(currentTime).getDay();
const isWeekend = [0, 6].includes(dayOfWeek);
if (isWeekend) {
return <p>It&apos;s the weekend!</p>;
}
return <p>It is not the weekend. :(</p>;
};
export default WeekendStatus;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment