Hooks API missing console.log

System Information
  • Strapi Version: 4.1.9
  • Operating System: Win10
  • Database: mysql
  • Node Version: 16.13.2
  • NPM Version: 8.1.2
  • Yarn Version: n/a

Hi,

When working with the strapi documentation and following the code example in the Hooks API chapter, the log “console.log(args)” didn’t show up anywhere. When there was other code in the same “bootstrap(app)”-section an error was thrown, which would mean that the code inside is getting reached, but the log doesn’t seem to log anywhere.

register(app) {
    app.createHook('new-hook/hooks');
   
    app.registerPlugin({
      id: pluginId,
      initializer: Initializer,
      isReady: false,
      name,
    });
  },

  bootstrap(app) {

    app.registerHook('new-hook/hooks', (...args) => {
      console.log("args-log: ", args)

      // ...
      return args
    });
  },

I followed the strapi documentation on hooks-api.

Does anyone see what’s wrong?

2 Likes

Great to see the same issue still exists after 2 years without any conclusion:) Documentation still says the same thing as well, yet this still happens, the callback does not fire.

For anyone else stumbling onto this, I suppose you have to actually call the hook by yourself in frontend part of your plugin, like this:

import { useStrapiApp } from "@strapi/helper-plugin";

const { runHookWaterfall } = useStrapiApp();
useEffect(()=> {
 runHookWaterfall("MY_PLUGIN")
},[])

Which isn’t noted anywhere in the docs for plugin development