Formik: onChangeValues callback

Created on 28 Aug 2017  路  7Comments  路  Source: formium/formik

Hi @jaredpalmer!

Is there any reason to not have an onChangeValues callback on formik where I can receive the props values of the form?

Best,

Most helpful comment

React has lifecycle events just for this exact thing: componentDidUpdate or componentWillReceiveProps if you need to setState. Just use the framework here.

All 7 comments

Can you give a use case? You should be able to achieve this with componentWillReceiveProps in the wrapped component, but I'm interested in whether you're doing somewhere where that doesn't fit

Agreed. Curious about use case here.

@guilhermedecampo Can you elaborate on what you are trying to accomplish?

Hi guys!

Yeah @skattyadz I used the componentWillReceiveProps for now. just wondering/asking if would be nice to have already in the component.. 馃

Use case:

We are developing an RN application which is necessary to change routes to fill up the form.
Imagine a full page select list. If user made some modification we need to save it somewhere before send it to the server.

Thanks guys.

Thanks for the follow up. Here are my thoughts for the thread and @jaredpalmer:

1) How much of a problem is it? Do other people have the same problem? Can it be solved with better documentation?
2) What's the ultimate conclusion of this change? If we add onChangeValues should we add onChangeIsValid and onChangeErrors and [...]. Is the answer a single onChange which includes all of those? Do we need to include the previous values so that you can see what was changed?

Formik's strength is that it allows you to achieve whatever you need without a complex API or complexity inside the library. If many people are rewriting the same behaviours then that's boilerplate; we should decide when those should be accommodated or when that's perfectly ok

React has lifecycle events just for this exact thing: componentDidUpdate or componentWillReceiveProps if you need to setState. Just use the framework here.

Another approach to the same problem: Are there HOCs we can recommend (or provide) that would solve common needs like this?

Taking inspiration from modules like:
https://www.npmjs.com/package/@hocs/with-callback-on-change
https://www.npmjs.com/package/map-props-changes-to-callbacks

Dumb question, but is there any way to do this when using the "render" style forms?

Was this page helpful?
0 / 5 - 0 ratings