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.

Support custom input components

See original GitHub issue

It would be really great to support custom components, eg. custom inputs, datepickers, timepickers, etc. As an option, a curried version of handleChange can be created, smth like handleChangeFor, so the usage could look as follows

Formik({
  mapPropsToValues: props => ({
    date: props.user.birthdate
  })
})(({handleChangeFor}) => (
  /// ...
  <SomeDatePicker
    onChange={handleChangeFor('date')}>
  // ...
));

I know this can be done using setFieldValue, but such utility function will help a lot. Avoiding imperative onChange={value => setFieldValue('date', value)} would be awesome. Here’s a sample implementation 😉

handleChangeFor (field) {
  return value => setFieldValue(field, value);
}

Would appreciate hearing your thoughts on this

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
husacommented, Aug 1, 2017

If anyone is curious, I ended up with hoc on top of Formik, smth like:

import {Formik} from 'formik';
import {compose, withProps} from 'recompact';

const withFormik = options => compose(
  Formik(options),
  withProps(({setFieldValue, setFieldTouched}) => ({
    handleChangeFor: field => ({value}) => {
      setFieldValue(field, value);
    },
    handleBlurFor: field => () => {
      setFieldTouched(field, true);
    }
  }))
);

export default withFormik;

Considering all your “custom” inputs trigger onChange or similar, with {value} as an argument.

0reactions
vathocommented, Jun 13, 2018

@eugene-kim I think the link has changed to https://github.com/jaredpalmer/formik#avoiding-new-functions-in-render - the heading in the README was changed, but the content of the paragraph is still the relevant bit you need.

/edit: relevant commit that changed the heading: https://github.com/jaredpalmer/formik/commit/ceb56399cf30c96fa9863a67df1e7dcaced746e4

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom input components - Sanity.io
This article will explore the pieces and steps necessary to create a custom input component from scratch.
Read more >
Building Custom Input Components for Blazor using InputBase
In this post, I'm going to point out some limitations with Blazor's input components. I'll then show how you can build your own...
Read more >
Custom input types - Vue Formulate
To do this, we need to write a custom component that handles the "autocomplete" input logic. Each type is designated as a component...
Read more >
Input types for custom components - Builder.io
When you create custom components to use in Builder, there are two required inputs and a number of optional inputs to help you...
Read more >
Vue custom input - DEV Community ‍ ‍
Most of us have faced it: build a custom input component. There are multiple reasons behind it but in general, it has custom...
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