{"size": 654, "ext": "js", "max_stars_repo_path": "src/deps-context.js", "max_stars_repo_name": "cloud-walker/react-depree", "max_stars_repo_stars_event_min_datetime": "2019-10-09T14:29:27.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-03T14:42:05.000Z", "max_issues_repo_path": "src/deps-context.js", "max_issues_repo_name": "cloud-walker/react-depree", "max_issues_repo_issues_event_min_datetime": "2020-04-09T17:17:47.000Z", "max_issues_repo_issues_event_max_datetime": "2020-04-15T12:52:32.000Z", "max_forks_repo_path": "src/deps-context.js", "max_forks_repo_name": "cloud-walker/react-depree", "max_forks_repo_forks_event_min_datetime": "2021-11-25T10:37:42.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-25T10:37:42.000Z"}
{"max_stars_count": 2, "max_issues_count": 4, "max_forks_count": 1, "avg_line_length": 22.5517241379, "max_line_length": 69, "alphanum_fraction": 0.6636085627}
import React from 'react'

const DepsContext = React.createContext(new Map())

/**
 * @typedef {[any, Object]} Deps
 * @param {Object} props
 * @param {Deps[]} props.depsMap
 */
export const DepsProvider = ({depsMap, ...props}) => {
  if (!depsMap) {
    throw new Error('DepsProvider is useless without a depsMap')
  }

  const value = React.useMemo(() => new Map(depsMap), [depsMap])

  return React.createElement(DepsContext.Provider, {...props, value})
}

export const provideDeps = realDeps => {
  const useDeps = function() {
    const depsMap = React.useContext(DepsContext)

    return {...realDeps, ...depsMap.get(this)}
  }

  return useDeps
}
