Skip to content

Is there a way to chain methods? #2817

Answered by fturmel
wsw70 asked this question in Q&A
Discussion options

You must be logged in to vote

You need a monolithic class or object for the chaining pattern to work, and that's counter to the date-fns architecture. Every function is an isolated module, which allows tree shaking and smaller bundle sizes (scroll down to the "exports analysis" section to see the size of each function: https://bundlephobia.com/package/date-fns).

With that said, you might enjoy the functional variant of the library. You can get pretty close to chaining when used alongside lodash's flow function. Keep in mind that the output of each step is sent as input of the next. https://date-fns.org/docs/fp/FP-Guide

import { addMonths, addMinutes } from "date-fns/fp";
import flow from "lodash.flow";

// example of …

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by leshakoss
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants