Farfetch / blackout

Blackout is the codename for the Farfetch Platform Solutions (FPS) projects. Useful to build e-commerce applications using the FPS APIs and integrating business logic.
MIT License
42 stars 15 forks source link

useAction Hook is obligating to install redux-related packages when using blackout-react #401

Closed dnamorim closed 1 year ago

dnamorim commented 2 years ago

Expected behaviour

When using the helpers from blackout-react, no redux-related packages should be required to be installed, if we use no features this package which don't require redux explicity:

import { headers, getTimeInMinutes } from '@farfetch/blackout-react`;

...

Actual behaviour

When we import helpers, like this:

import { headers, getTimeInMinutes } from '@farfetch/blackout-react`;

...

as the @farfetch/blackout-react exports useAction on the helpers/index.ts, it requires the installation of redux and react-redux.

Steps to reproduce

  1. Open a project without redux and react-redux installed
  2. Try to make the following import
    import { headers, getTimeInMinutes } from '@farfetch/blackout-react`;
  3. Run the project

Context/environment

This happens on projects that have installed @farfetch/blackout-react but doesn't have redux and react-redux and need to use some react helpers.

Possible fix

  1. Don't export helpers/useAction.ts directly on the helpers/index.ts, and require users to use a explicitly path, like:

    import { useAction } from @farfetch/blackout-react/helpers/withRedux
    // or
    import useAction from @farfetch/blackout-react/helpers/useAction
  2. Remove useAction, as this function is known for having performance issues and is not recommended (see https://react-redux.js.org/api/hooks#recipe-useactions) and pass the decision to use that for the tenant

jhairabreu commented 1 year ago

Fixed in #500