JSFiddle - React, Tailwind, and code Playground

JavaScript

function fn1(cb) {
  console.log('fn1')
  
  if (cb) {
    return cb()
  }
}

function fn2(cb) {
  console.log('fn2')
  
  if (cb) {
    return cb()
  }
}

function fn3() {
  console.log('fn3')
}

function chain(...args) {
  if (args.length > 0 && typeof args[0] === 'function') {
    return args[0](() => chain.apply(null, args.slice(1)))
  }
}

chain(fn1, fn2, fn3)