Efficient way of using custom components
See original GitHub issueCurrent way of passing props to custom form components is similar to this one:
<Input
name="username"
label="Username or E-mail"
errors={errors.username}
touched={touched.username}
onChange={handleChange}
onBlur={handleBlur}
/>
<Input
type="password"
name="password"
label="Password"
errors={errors.password}
touched={touched.password}
onChange={handleChange}
onBlur={handleBlur}
/>
This 2 inputs already need like 15 lines in editor. As you can see, we pass the same props to both of them -errors
, touched
, handleChange
and handleBlur
.
Is it somehow possible to automatically pass this props so we can reduce the code to something like this:
<Input name="username" label="Username or E-mail" />
<Input type="password" name="password" label="Password" />
Same 2 inputs, but only 2 lines in editor. Maybe it’s just me, but it’s much easier to have small compact forms.
One of possible solutions I can think of - a Field
component, that gets all passed form props (via context
?) and Input
is a wrapper over this component.
Maybe there are other ideas/ways of solving this?
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
10 Custom Component Best Practices - CLIMB
Custom React components are a powerful way to extend the functionality of your app. Here are 10 best practices to follow when creating...
Read more >Custom Element Best Practices - web.dev
Custom elements let you construct your own HTML tags. This checklist covers best practices to help you build high quality elements.
Read more >Best practices to build Web Components - Medium
Try to create simple components with one kind of functionality. ... This means that you cannot have two Custom Elements within the same...
Read more >Strategies for building customizable components - MUI
This article reviews several different approaches that a developer might take to customize UI components, as well as the various tradeoffs ...
Read more >How To Create Custom Components in React - DigitalOcean
There are two types of custom component: class-based and functional. The first component you are going to make is a class-based component. You ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@VladShcherbin Plan is to merge it to master next week.
@VladShcherbin Correct see the
<Field/>
component.