"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.createContainer = createContainer;
exports.useContainer = useContainer;

var _react = _interopRequireDefault(require("react"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function createContainer(useHook) {
  var Context = _react.default.createContext(null);

  function Provider(props) {
    var value = useHook(props.initialState);
    return /*#__PURE__*/_react.default.createElement(Context.Provider, {
      value: value
    }, props.children);
  }

  function useContainer() {
    var value = _react.default.useContext(Context);

    if (value === null) {
      throw new Error('Component must be wrapped with <Container.Provider>');
    }

    return value;
  }

  return {
    Provider: Provider,
    useContainer: useContainer
  };
}

function useContainer(container) {
  return container.useContainer();
}