You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.3 KiB

2 years ago
"use strict";
exports.__esModule = true;
exports.createStoreHook = createStoreHook;
exports.useStore = void 0;
var _react = require("react");
var _Context = require("../components/Context");
var _useReduxContext2 = require("./useReduxContext");
/**
* Hook factory, which creates a `useStore` hook bound to a given context.
*
* @param {React.Context} [context=ReactReduxContext] Context passed to your `<Provider>`.
* @returns {Function} A `useStore` hook bound to the specified context.
*/
function createStoreHook(context) {
if (context === void 0) {
context = _Context.ReactReduxContext;
}
var useReduxContext = context === _Context.ReactReduxContext ? _useReduxContext2.useReduxContext : function () {
return (0, _react.useContext)(context);
};
return function useStore() {
var _useReduxContext = useReduxContext(),
store = _useReduxContext.store;
return store;
};
}
/**
* A hook to access the redux store.
*
* @returns {any} the redux store
*
* @example
*
* import React from 'react'
* import { useStore } from 'react-redux'
*
* export const ExampleComponent = () => {
* const store = useStore()
* return <div>{store.getState()}</div>
* }
*/
var useStore = /*#__PURE__*/createStoreHook();
exports.useStore = useStore;