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

useState Hook Does Not Run in Body of Dialog Component #4

Open
frastlin opened this issue Mar 10, 2020 · 2 comments
Open

useState Hook Does Not Run in Body of Dialog Component #4

frastlin opened this issue Mar 10, 2020 · 2 comments

Comments

@frastlin
Copy link

Hello,
I have a form on my dialog and I'm using the useState hook:

const [ email, setEmail ] = useState(props.email)

but when I console.log(email) after this, I get undefined. If I run the component outside the dialog, then it works just fine.

@tomivirkki
Copy link
Owner

Hi,
The following works fine for me (foobar@vaadin.com is logged to the console):

<Dialog opened>
  <Form email="foobar@vaadin.com"></Form>
</Dialog>

Form.js

import * as React from 'react';

export default (props) => {

  const [ email, setEmail ] = React.useState(props.email);

  console.log(email);

  return <div>
    <input />
    <input />
  </div>
}

@frastlin
Copy link
Author

Hello, sorry, I guess it has something to do with the component not updating if the prop that is passed in is null first, then is changed to a value later. I fixed the problem by having the dialog not render if the field it needed was empty.

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