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

React warning: Cannot update a component while rendering a different component when using ...text in child component #163

Open
karenpeng opened this issue Dec 29, 2022 · 0 comments

Comments

@karenpeng
Copy link

I have a use case that I have to pass formState and text from parent to child component:

const Child = ({text, formState}) => {
  return (
     <input {...text('name')} />
  );
}
const Parent = () => {
  const [formState, { text }] = useFormState<QueryHistoryFilterFormState>(filters);
 return (
   <Child text={text} formState={formState}/>
 );
}

However, this will cause warnings since React v16.3.0 because the Child is setting state during render. See more explanations in: https://gorannikolovski.com/blog/cannot-update-a-component-while-rendering-a-different-component-react-native.

Any suggestions or workarounds?

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

1 participant