question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Efficient way of using custom components

See original GitHub issue

Current 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:closed
  • Created 6 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jaredpalmercommented, Aug 31, 2017

@VladShcherbin Plan is to merge it to master next week.

1reaction
jaredpalmercommented, Aug 31, 2017

@VladShcherbin Correct see the <Field/> component.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found