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

useInput/onChange not working in initial useEffect. #6308

Closed
hereblur opened this issue May 25, 2021 · 2 comments
Closed

useInput/onChange not working in initial useEffect. #6308

hereblur opened this issue May 25, 2021 · 2 comments

Comments

@hereblur
Copy link

I'm trying to implement custom input using useInput.
The initial value of input come from other context. I try to use 'onChange' to update value of the input but it's not update value as expected.

However It's working if I delay a bit using setTimeout().

What you were expecting:
onChange inside useEffect should update value of input.

What happened instead:
onChange inside useEffect not update value of input.

Steps to reproduce:
Implemented as example code

Related code:
https://codesandbox.io/s/currying-bash-4o68c?file=/src/RandomInput.tsx , try create new Post.

const {
    input: { onChange, name, value },
    meta: { touched, error }
  } = useInput({ ...props, source });

  useEffect(() => {

    onChange(Math.random() * 99999);
    // This should update value of input when render.
 
    console.log("ONCHANGE CALLED [useEffect]");
  }, []);

Other information:

Environment

  • React-admin version: 3.15.1
  • Last version that did not exhibit the issue (if applicable): I think 3.7 was working before I updated.
  • React version: Any
  • Browser: Any
  • Stack trace (in case of a JS error):
@fzaninotto
Copy link
Member

We've fixed an issue about defaultValue in Edit views (#6272) in 3.15.2. Can you test it and report if it fixes your issue?

@fzaninotto
Copy link
Member

No news for some time, closing.

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

No branches or pull requests

2 participants