Adding More Options to useDependency Hook

Examine how to enhance the “useDependency” hook to cover more use cases.

Configuration for dependency object

In the previous lesson, the content was the only available option in the dependency object. Now, two new options are added here:

  • The strategy string tells the hook how to get the requested prop. Valid values can be like fetch, store, cache etc.
  • The store object can be provided with external actionCreator to call after prop fetch is successful.
{
    content: 'user',
    strategy: 'fetch',
    store: {
      actionCreator: refreshUser
    }
}

Config options object

The options object provides general settings for useDependency hook. An addition to options is the store object. It contains two functions dispatch and getState.

{
  store: {
    dispatch,
    getState: () => globalState
  }
}

Both of the above objects can be found in App.js in the following exercise.

Get hands-on with 1400+ tech skills courses.