Data is not seen in the lifecycle hooks for the component inside a collection

I try to get the params from the lifecyclehook. The data for the component is not showing. Therefore, I cannot access to the data. Is there available options to reveal the data for the component inside the lifecycle hook event methods.

1 Like

Hi, I’m stuck with the same problem and it seams like this possibility has been removed in v4.
Btw we are not the only ones having this issue, in fact there is a feature request for this and you can vote for it here

1 Like

I found out another way to get the components data with raw query using strapi.db.connection() in lifecycles hook. I think you can also try like that. There may be another feasible solution for that. Welcome any suggestions.

const user = await strapi.db.connection
  .select("*")
  .from(`${process.env.DATABASE_SCHEMA}.components_userinfo_user_infos`)
  .where({ id: data.userInfo.id });

Thank you for the tip :blush:
It seems a good workaround so I’ll try that way

1 Like

Yes seems pretty daft you can’t access the data easily, but after much digging I found this option to access the data

  async beforeUpdate(event) {
    const { data, where, select, populate } = event.params;
    const ctx = strapi.requestContext.get();
    console.log(ctx.request.body);
  }

Although not sure how much it helps as there no obvious way to alter the data before saving it