Code Monkey home page Code Monkey logo

Comments (10)

erikras avatar erikras commented on May 19, 2024

That's an anti-pattern. The general rule of thumb for Redux, and React in general, is:

If you can calculate it from the state, don't store it in the state.

The less state the better.

If you want to do it anyway, you'll need your own Redux reducer, much like how this form keeps saveError separate, to keep it. This library isn't going to support keeping validation state in the store.

from redux-form.

vkrol avatar vkrol commented on May 19, 2024

Thanks. But what if I need to show the form validation state (valid/invalid) in an another component?

from redux-form.

erikras avatar erikras commented on May 19, 2024

Two options:

  • connect() to the form data and import and run your validator in the other component.
  • Just connectReduxForm() in the other component and read the props. It doesn't matter how many components connect to the same form.

from redux-form.

erikras avatar erikras commented on May 19, 2024

#49 will help with this when it gets implemented.

from redux-form.

vkrol avatar vkrol commented on May 19, 2024

Just connectReduxForm() in the other component and read the props. It doesn't matter how many components connect to the same form.

Thanks. So if I have async validation and i will connect two components to the same form, then the asynchronous validation will be performed twice?

from redux-form.

erikras avatar erikras commented on May 19, 2024

Good question. No, the async validation will only be fired when the BLUR action is sent, so as long as you are only sending it from one of the components (which is necessarily the case), the async validation will only happen once, but will be displayed (available to) both components. Make sense?

from redux-form.

vkrol avatar vkrol commented on May 19, 2024

Thanks!

from redux-form.

anatoliyarkhipov avatar anatoliyarkhipov commented on May 19, 2024

Sorry, I still not understand.

Following the discussion, if I have two components which want to know about the validation state, then I should connect them both to the form and should pass the same validation function to connectReduxForm. Is it correct?

If it is, then it means, that the validation function will be called twice, during rendering of the first and the second components. How to avoid this?

from redux-form.

erikras avatar erikras commented on May 19, 2024

@anatoliyarkhipov Your validation function should be quite fast, but if it isn't, then memoize it.

from redux-form.

lock avatar lock commented on May 19, 2024

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

from redux-form.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.