Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hook component can not use useSelector to get form values #4733

Open
cc616 opened this issue May 25, 2021 · 1 comment
Open

hook component can not use useSelector to get form values #4733

cc616 opened this issue May 25, 2021 · 1 comment
Labels

Comments

@cc616
Copy link

cc616 commented May 25, 2021

Subject of the issue

Your environment

Software Version(s)
redux-form 8.2.4
redux 4.1.0
react-redux 7.2.4
react 17.0.2
react-dom 17.0.2
Browser
Operating System

Steps to reproduce

https://codesandbox.io/s/redux-form-example-de1di?file=/src/App.tsx

Expected behaviour

work

Actual behaviour

can not work
Maximum update depth exceeded.

Other information

how to get form values with hook component

@cc616 cc616 added the bug label May 25, 2021
@mj12albert
Copy link

Nothing to do with useSelector

<Field
            name="firstName"
            component="input"
            type="text"
            validate={[maxLength(1)]} <-------------- this is the cause
            placeholder="First Name"
          />

if you are using field validation, the functions passed to the validate prop must be static, e.g.

const maxLength = max => value =>
  value && value.trim().length > max ?  'error' : undefined;

const maxLength1 = maxLength(1);

<Field
            name="firstName"
            component="input"
            type="text"
            validate={[maxLength1]}
            placeholder="First Name"
          />

alternatively, use sync validation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants