From e4fc2347c6f4af2733056c4e20f26cb5aefa11d2 Mon Sep 17 00:00:00 2001 From: Nicco Date: Fri, 25 Oct 2019 10:58:00 +0200 Subject: [PATCH] Update README.md --- README.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/README.md b/README.md index 83a9a1c..42b857c 100644 --- a/README.md +++ b/README.md @@ -164,6 +164,35 @@ const Form = () => { } ``` +### Dynamic Fields + +Sometimes you don't know all the fields upfront. You can simply define a generic type and assign it to the initial object. Of course type assistance is limited in this case as formhero cannot be sure what keys are valid. + +```typescript +import React from "react"; +import ReactDOM from "react-dom"; +import { useForm } from "formhero"; + +type MyForm = { [field: string]: string | number }; + +const init: MyForm = { + username: "unicorn", + password: "" +}; + +const Form: React.FC = () => { + const { field, form, errors } = useForm(init); + + return ( +
+ + + +
+ ); +}; +``` + ## 📖 Documentation ### `useForm`