Skip to content

Commit 21cbcf0

Browse files
committed
feat: add existing props to context in dynamicParametrize
* If the user wants to base their dynamic prop override on some existing prop values (e.g. filtering the options of a dropdown according to the value of another field), it is significantly easier for them if these values are available through the `propsFactory` function
1 parent 7c7a975 commit 21cbcf0

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/lib/utils/fieldComponents.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as React from "react";
66
* context variables.
77
*
88
* Currently, the following arguments are passed into the `propsFactory` function:
9+
* - `existingProps`: the props originally passed into the component before the override
910
* - `formValues`: an object of the values in the Formik form state
1011
*
1112
* The `propsFactory` function should return an object of the props to be used for overriding the
@@ -19,7 +20,7 @@ import * as React from "react";
1920
export function dynamicParametrize(Component, propsFactory) {
2021
const ParametrizedComponent = (props) => {
2122
const { values } = useFormikContext();
22-
const extraProps = propsFactory({ formValues: values });
23+
const extraProps = propsFactory({ existingProps: props, formValues: values });
2324

2425
// Store the original component in an attribute
2526
if (Component.originalComponent) {

0 commit comments

Comments
 (0)