Giter Site home page Giter Site logo

Comments (11)

bluebill1049 avatar bluebill1049 commented on July 18, 2024 2

hey @kotarella1110 think it's better to useCallback at app level, then user will be in control if external dependency changed.

from documentation.

bluebill1049 avatar bluebill1049 commented on July 18, 2024 1

This is not a bug and intended behavior.

Screen Shot 2020-02-21 at 7 45 11 pm

Feel free to improve.

from documentation.

kotarella1110 avatar kotarella1110 commented on July 18, 2024 1

Sure, but in my case, I'm doing validation based on a dynamic validation schema, (the schema is a prop). I can force re-mount the whole component whenever the schema changes, sure, but confirming this either as a bug or as intended would help a lot of people if pointed out in docs.

Perhaps validation context can work in those cases, and again it should be pointed out in docs.

validationContext can't work in those cases.
We need to leave the validationContext outside of the component, just like the validationResolver function.

already fixed react-hook-form/react-hook-form@c00722b

from documentation.

bluebill1049 avatar bluebill1049 commented on July 18, 2024

Try this: https://codesandbox.io/s/agitated-fire-w9myu

from documentation.

kotarella1110 avatar kotarella1110 commented on July 18, 2024

@bluebill1049 Should validationResolver be memoized at app-level?
Why aren't you using the useCallback inside the useForm method to memoize the validationResolver?

from documentation.

anilanar avatar anilanar commented on July 18, 2024

Lovely, I’ll submit a PR for the docs.

from documentation.

bluebill1049 avatar bluebill1049 commented on July 18, 2024

Awesome thanks.

from documentation.

anilanar avatar anilanar commented on July 18, 2024

@bluebill1049 On the other hand, when using useCallback with a dependency, useForm exhibits the same behaviour as the one reported here, whenever the reference for validationResolver changes.

I assume when that does happen, registered field elements become unregistered. And because those fields are not remounted, they won't trigger register again. Am I correct?

So until that is changed/fixed, I shouldn't suggest using callbacks that rely on the component state in the docs.

from documentation.

bluebill1049 avatar bluebill1049 commented on July 18, 2024

It's almost easier and better to leave resolver function outside the component.

https://react-hook-form.com/api/#validationResolver

from documentation.

anilanar avatar anilanar commented on July 18, 2024

Sure, but in my case, I'm doing validation based on a dynamic validation schema, (the schema is a prop). I can force re-mount the whole component whenever the schema changes, sure, but confirming this either as a bug or as intended would help a lot of people if pointed out in docs.

Perhaps validation context can work in those cases, and again it should be pointed out in docs.

from documentation.

bluebill1049 avatar bluebill1049 commented on July 18, 2024

moving it under website to improve the doc

from documentation.

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.