Strapi Hooks - Use cases

hello everyone!

I’m pretty close to finish the “Strapi Hooks” article I’ve been writing for the last couple of months.
It’s a review and comparison on the three different types of hooks in Strapi:

There’s just one section that I’m looking to improve, which is: providing interesting use case examples
for each type of hook.

As I don’t have enough material about this topic, thought I’d reach out to the community in search for
cool use cases where you may have used hooks in a project (or not, it could just be anything that occurs to you).

Let me kickstart the conversation with what I have so far:

All suggestions are very welcome :slight_smile:
Thanks!

4 Likes

Hey @ramigs,

Looking forward to reading your article, I hope it really reflects all the possibilities in this case the hooks for customisation with Strapi. I have some to add to your list.

use cases/examples:

  • Server hooks:
    The docs have an detailed guide on how to integrate an third party client (in this case GitHub) with strapi, worth mentioning.
    Nice to see strapi-hook-algolia there :wink: (it uses also the lifecycle hooks in its implementation).
  • Lifecycle hooks:
    Sending email/notification on create/update.
1 Like

Something I’ve been thinking of: a hook to clear cloudflare CDN cache when content is edited.
(I can imagine how that would be doable with REST API, graphql - would be tricky, if you use the automatic persisted queries you have to create the same hashed query string to create an exact URL to send to them… IDK, when I’m thinking of doing that I’ll open that as its own issue)

1 Like

If interested, I have a blog post that details how to integrate Strapi with Cloudflare caching - see https://blather.aidanwhiteley.com/strapi-and-cloudflare/

I took a quick look, looks really cool! I’ll have to take a closer look.
My site is now a static site, so I have a hook which rebuilds and then clears the CDN.
With a bigger site, I’d want to just clear files which changed - which is easier then in your example, because there’s no API calls from the client, just static html and JSON.

Hi Guys
Hope you guys are doing well

As I have implemented custom hook in my strapi , Its not working ,nothing is showing in terminal ,I can not able to get the problem.
Can you please help

Hello all ,

i am unable to run my custom server hook,can someone please help.

i have my config file in ./config/hook.js

module.exports = ({ env }) => ({
  settings: {
   redis: {
      enabled: true,
      db: 0,
      host: env("REDIS_HOST"),
      port: env.int("REDIS_PORT"),
    },
  },
});

i have my hook in ./hooks/redis/index.js

const Redis = require("ioredis");
module.exports = (strapi) => {
  return {
    async initialize() {
      console.log(" hello it should work");    
    },
  };
};

it works in v3 but in v4 it does not work

2 Likes

Did you found a solution for this in v4?

Thanks!