can not set state in render (#483)

This commit is contained in:
Erik Jan de Wit 2021-03-31 21:07:04 +02:00 committed by GitHub
parent 74aee6090d
commit 6102770fbf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,4 +1,4 @@
import React from "react";
import React, { useEffect } from "react";
import { useTranslation } from "react-i18next";
import { ArrayField, UseFormMethods } from "react-hook-form";
import { ActionGroup, Button, TextInput } from "@patternfly/react-core";
@ -68,9 +68,11 @@ export const AttributesForm = ({
const watchLast = watch(`attributes[${fields.length - 1}].key`, "");
useEffect(() => {
if (fields.length === 0) {
append({ key: "", value: "" });
}
}, [fields]);
return (
<>