mercredi 7 avril 2021

Is it a bad practice to create a hook that doesn't access to React lifecycle?

I've created a hook called useFilestack that now abstracts the logic to upload a file from a binary, but in the future it can grow as needed. So it looks like this:

const useFilestack = () => {
  const upload = (binary: string) => {
    const file = Buffer.from(binary, 'binary').toString('base64');

    const filestack = client.init(apiKey);

    filestack.upload(file);
  };

  return {
    upload,
  };
};

As you can see, it doesn't access to the React lifecycle using for example some useEffect or useState.

Is that a bad practice? I'm gonna use this in some many place so it makes sense for me to abstract it in some place.

Aucun commentaire:

Enregistrer un commentaire