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

[Field]cant use getValues while setValues before init with parseName=true #792

Closed
1 task
bindoon opened this issue Jun 14, 2019 · 4 comments
Closed
1 task
Assignees

Comments

@bindoon
Copy link
Member

bindoon commented Jun 14, 2019

  • I have searched the issues of this repository and believe that this is not a duplicate.

Version

Component

Field

Environment

all

Steps to reproduce

class Main extends React.Component {
  constructor(props) {
    super(props);
    this.field = new Field(this, {parseName: true});
    this.field.setValues({a:1});
  }
  render() {
    this.field.getValues(); // should be {a:1} but actually get {}
    return <div>
    {this.state.show ? <input {...init('a')} />: null}
    </div>
  }
}
@bindoon
Copy link
Member Author

bindoon commented Jun 14, 2019

we do this with react-hooks issues. i think we should cache values directly for getValues/getValue/setValue/setValues

@jdkahn
Copy link
Contributor

jdkahn commented Jun 17, 2019

Can you clarify the use case for this? In the above example, the values should be set in the Field constructor. If the value is being set via api call then it would be called after ComponentDidMount so the init would already be called. As I understand it, Field cannot support react-hooks at the moment.

@bindoon
Copy link
Member Author

bindoon commented Jun 17, 2019

@jdkahn just want to save values, ant init may be not called at first render

  render() {
    this.field.getValues(); // should be {a:1} but actually get {}
    return <div>
    {this.state.show ? <input {...init('a')} />: null}   // while show=true init(a) will be called
    </div>
  }

@jdkahn
Copy link
Contributor

jdkahn commented Jun 17, 2019

@bindoon

  1. I cannot see a reasonable case where setValues is called before init (see my above comment). For it to work with parseName it would have to just store the entire object passed in a new field attribute, which I feel is adding unnecessary complexity if we don't have a clear use case.

  2. If calling getValues before inputs are first rendered, then values could be assigned on Field construction. As of now, we iterate through field names, which will return nothing. This is an easy fix to return initValue as default value.

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

No branches or pull requests

2 participants