MCPcopy
hub / github.com/jaredpalmer/formik / FieldArrayInner

Class FieldArrayInner

packages/formik/src/FieldArray.tsx:140–390  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

138};
139
140class FieldArrayInner<Values = {}> extends React.Component<
141 FieldArrayConfig & { formik: FormikContextType<Values> },
142 {}
143> {
144 static defaultProps = {
145 validateOnChange: true,
146 };
147
148 constructor(props: FieldArrayConfig & { formik: FormikContextType<Values> }) {
149 super(props);
150 // We need TypeScript generics on these, so we'll bind them in the constructor
151 // @todo Fix TS 3.2.1
152 this.remove = this.remove.bind(this) as any;
153 this.pop = this.pop.bind(this) as any;
154 }
155
156 componentDidUpdate(
157 prevProps: FieldArrayConfig & { formik: FormikContextType<Values> }
158 ) {
159 if (
160 this.props.validateOnChange &&
161 this.props.formik.validateOnChange &&
162 !isEqual(
163 getIn(prevProps.formik.values, prevProps.name),
164 getIn(this.props.formik.values, this.props.name)
165 )
166 ) {
167 this.props.formik.validateForm(this.props.formik.values);
168 }
169 }
170
171 updateArrayField = (
172 fn: Function,
173 alterTouched: boolean | Function,
174 alterErrors: boolean | Function
175 ) => {
176 const {
177 name,
178
179 formik: { setFormikState },
180 } = this.props;
181
182 setFormikState((prevState: FormikState<any>) => {
183 let updateErrors = createAlterationHandler(alterErrors, fn);
184 let updateTouched = createAlterationHandler(alterTouched, fn);
185
186 // values fn should be executed before updateErrors and updateTouched,
187 // otherwise it causes an error with unshift.
188 let values = setIn(
189 prevState.values,
190 name,
191 fn(getIn(prevState.values, name))
192 );
193
194 let fieldError = alterErrors
195 ? updateErrors(getIn(prevState.errors, name))
196 : undefined;
197 let fieldTouched = alterTouched

Callers

nothing calls this directly

Calls 15

removeMethod · 0.95
popMethod · 0.95
setInFunction · 0.90
getInFunction · 0.90
isEmptyArrayFunction · 0.90
createAlterationHandlerFunction · 0.85
copyArrayLikeFunction · 0.85
swapFunction · 0.85
moveFunction · 0.85
insertFunction · 0.85
replaceFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…