how to use the isyesterday function from the date-fns library in typescript

You can use the isYesterday function from the date-fns library in TypeScript by importing it and passing in a Date object.

Here's an example:

index.ts
import { isYesterday } from 'date-fns';

const date = new Date('2021-07-20');

if (isYesterday(date)) {
  console.log('Yesterday');
} else {
  console.log('Not yesterday');
}
175 chars
10 lines

In the example above, we import the isYesterday function from the date-fns library. We then create a Date object for the date 2021-07-20. We pass this Date object to the isYesterday function which returns a boolean indicating whether the date was yesterday.

We then check the boolean value and log Yesterday if the date was yesterday or Not yesterday if it wasn't.

gistlibby LogSnag