Maximilian: Now let's talk about simplifications
and what else we could do.
Now you could definitely try to outsource more Logic.
You could try to build individual input components
which contained some validation logic or whatever.
You could build an overall form component
which handles a lot of that.
You could build more custom hooks,
which for example, return entirely pre-configured inputs
or forms.
And attached you'll find an article on that
which might also be interesting to you
where we also build a complete use form hook
which even spits out readily configured
input elements which you can use in JSX.
I want to focus on the basics here, though,
and that is already a long module.
For me, it mattered to explain
how we can use what we learned about React
to build great user experiences
and to build forms and form behaviors
that make sense to our users.
That feel good to our users.
And at the same time, I, of course, also wanted to show you
that this can lead to a lot of unnecessary code
and therefore building something like this
custom use input hook can reduce code duplication
and allows us to reuse Logic
even though we now, of course,
still have some replicated code,
but it is distinct enough, I would argue.
Nonetheless, you can dive into building more
elaborate custom hooks
and this attached article might be interesting for that.
In addition, there also are third-party libraries
that could be interesting to you.
For example, Formik.
Formik is a very popular third-party library
for working with forms
and you can dive into the official docs
to learn more about it.
It's not really using hooks that much,
it's more using components
and patterns we know from older versions of React,
so to say.
But nonetheless, it's a great library
when it comes to rendering forms
and dealing with more complex forms and validation.
Again, you can explore the official docs
to learn how it works.
The core idea is that you don't have to write much
state management logic
but that instead you write your validation logic,
you define your fields,
and then let Formik do the rest.
A little bit as we did it with our custom-use input hook.
There we also focused on passing in the validation logic
and the hook then manages the state for us.
Formik then just has more use cases
and outsources even more Logic,
or allows us to outsource even more Logic to it.
So that might definitely be worth a look.
Now for this course though,
I'm happy with this approach.
You again got more practice
with working with custom hooks,
and you really see what's going on behind the scenes.
Now you are definitely well prepared
to handle the forms and user input
in your next project, and of course
we are also going to work a bit more with forms
in the course projects you'll find
in the rest of this course.