setCurrentValue(e.target.value)}
- />
+
+ setCurrentValue(e.target.value)}
+ />
+
);
};
-export default observer(TextArea);
+export default TextArea;
diff --git a/src/client/hocs/withStore.js b/src/client/hocs/withStore.js
new file mode 100644
index 0000000..2de13a7
--- /dev/null
+++ b/src/client/hocs/withStore.js
@@ -0,0 +1,47 @@
+import { useOptions } from 'client/hooks/useOptions';
+import { useStatus } from 'client/hooks/useStatus';
+import { useStoreValue } from 'client/hooks/useStoreValue';
+import { useValidation } from 'client/hooks/useValidation';
+import { DEFAULT_DEBOUNCE_DELAY } from 'core/constants/debounce';
+import { observer } from 'mobx-react';
+import React from 'react';
+
+export const withStoreValue = Component => ({
+ name,
+ valueName,
+ computedValue,
+ validation,
+ ...params
+}) => {
+ const ComponentWithStore = () => {
+ const { value, setCurrentValue, debouncedValue } = useStoreValue({
+ computedValue,
+ valueName,
+ debounceDelay: DEFAULT_DEBOUNCE_DELAY,
+ });
+ const { status } = useStatus(name);
+ const { isValid, validateStatus, message } = useValidation({
+ elementName: name,
+ value: debouncedValue,
+ validation: validation || {
+ errorMessage: '',
+ validator: () => {},
+ },
+ });
+ const { options, filter } = useOptions(name);
+
+ return (
+
+ );
+ };
+ return observer(ComponentWithStore);
+};
diff --git a/src/client/hocs/withStore.tsx b/src/client/hocs/withStore.tsx
deleted file mode 100644
index 75d55f6..0000000
--- a/src/client/hocs/withStore.tsx
+++ /dev/null
@@ -1,25 +0,0 @@
-import React, { ComponentType } from "react";
-// import hoistNonReactStatics from "hoist-non-react-statics";
-import { useStores } from "../hooks/useStores";
-import { useObserver } from "mobx-react";
-
-export type TWithStoreHOC = (
- Component: ComponentType
-) => (props: P) => JSX.Element;
-
-export const withStore: TWithStoreHOC = (WrappedComponent) => (props) => {
- const ComponentWithStore = () => {
- const stores = useStores();
-
- return ;
- };
-
- ComponentWithStore.defaultProps = { ...WrappedComponent.defaultProps };
- ComponentWithStore.displayName = `WithStores(${
- WrappedComponent.name || WrappedComponent.displayName
- })`;
-
- // hoistNonReactStatics(ComponentWithStore, WrappedComponent);
-
- return ;
-};
diff --git a/src/core/constants/debounce.js b/src/core/constants/debounce.js
index 0993b7e..aab9729 100644
--- a/src/core/constants/debounce.js
+++ b/src/core/constants/debounce.js
@@ -1,2 +1 @@
-export const TEXT_INPUT_DEBOUNCE_DELAY = 650;
-export const DEFAULT_DEBOUNCE_DELAY = 0;
+export const DEFAULT_DEBOUNCE_DELAY = 250;