remix-validated-form 4.1.0-beta.2 → 4.1.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/browser/ValidatedForm.js
CHANGED
@@ -91,13 +91,18 @@ function formEventProxy(event) {
|
|
91
91
|
},
|
92
92
|
});
|
93
93
|
}
|
94
|
+
const useFormAtom = (formId) => {
|
95
|
+
const formAtom = formRegistry(formId);
|
96
|
+
useEffect(() => () => formRegistry.remove(formId), [formId]);
|
97
|
+
return formAtom;
|
98
|
+
};
|
94
99
|
/**
|
95
100
|
* The primary form component of `remix-validated-form`.
|
96
101
|
*/
|
97
102
|
export function ValidatedForm({ validator, onSubmit, children, fetcher, action, defaultValues: providedDefaultValues, formRef: formRefProp, onReset, subaction, resetAfterSubmit = false, disableFocusOnError, method, replace, id, ...rest }) {
|
98
103
|
var _a;
|
99
104
|
const formId = useFormId(id);
|
100
|
-
const formAtom =
|
105
|
+
const formAtom = useFormAtom(formId);
|
101
106
|
const contextValue = useMemo(() => ({
|
102
107
|
formId,
|
103
108
|
action,
|
package/build/ValidatedForm.js
CHANGED
@@ -116,13 +116,18 @@ function formEventProxy(event) {
|
|
116
116
|
},
|
117
117
|
});
|
118
118
|
}
|
119
|
+
const useFormAtom = (formId) => {
|
120
|
+
const formAtom = (0, state_1.formRegistry)(formId);
|
121
|
+
(0, react_2.useEffect)(() => () => state_1.formRegistry.remove(formId), [formId]);
|
122
|
+
return formAtom;
|
123
|
+
};
|
119
124
|
/**
|
120
125
|
* The primary form component of `remix-validated-form`.
|
121
126
|
*/
|
122
127
|
function ValidatedForm({ validator, onSubmit, children, fetcher, action, defaultValues: providedDefaultValues, formRef: formRefProp, onReset, subaction, resetAfterSubmit = false, disableFocusOnError, method, replace, id, ...rest }) {
|
123
128
|
var _a;
|
124
129
|
const formId = useFormId(id);
|
125
|
-
const formAtom = (
|
130
|
+
const formAtom = useFormAtom(formId);
|
126
131
|
const contextValue = (0, react_2.useMemo)(() => ({
|
127
132
|
formId,
|
128
133
|
action,
|
package/package.json
CHANGED
package/src/ValidatedForm.tsx
CHANGED
@@ -191,6 +191,12 @@ function formEventProxy<T extends object>(event: T): T {
|
|
191
191
|
}) as T;
|
192
192
|
}
|
193
193
|
|
194
|
+
const useFormAtom = (formId: string | symbol) => {
|
195
|
+
const formAtom = formRegistry(formId);
|
196
|
+
useEffect(() => () => formRegistry.remove(formId), [formId]);
|
197
|
+
return formAtom;
|
198
|
+
};
|
199
|
+
|
194
200
|
/**
|
195
201
|
* The primary form component of `remix-validated-form`.
|
196
202
|
*/
|
@@ -212,7 +218,7 @@ export function ValidatedForm<DataType>({
|
|
212
218
|
...rest
|
213
219
|
}: FormProps<DataType>) {
|
214
220
|
const formId = useFormId(id);
|
215
|
-
const formAtom =
|
221
|
+
const formAtom = useFormAtom(formId);
|
216
222
|
const contextValue = useMemo<InternalFormContextValue>(
|
217
223
|
() => ({
|
218
224
|
formId,
|