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

Linked inputs error: Cannot update a component from inside the function body of a different component #4606

Closed
manuelamaria opened this issue Mar 30, 2020 · 1 comment

Comments

@manuelamaria
Copy link

What you were expecting:
I have two linked inputs on a form - a SelectInput and a CheckboxGroupInput. I expect to be able to change the options of the group input depending on the selection in the select. For this, I use the FormDataConsumer.

What happened instead:
This works, so the options update in the group, but whenever I change the selection, I have a warning in the console:

Warning: Cannot update a component from inside the function body of a different component.
    in CheckboxGroupInput (at EditFormAlt.js:26)
    in FormDataConsumerView (created by FormDataConsumer)
    in FormDataConsumer (at EditFormAlt.js:23)

Related code:

<SimpleForm {...props}>
    <SelectInput source='provider' choices={providerChoices} />
    <FormDataConsumer>
        {({ formData, ...rest }) =>
            formData.provider && (
                        <CheckboxGroupInput
                            source='correlations'
                            choices={getByProvider(formData.provider)}
                        />
            )
         }
    </FormDataConsumer>
</SimpleForm>

Other information:

Environment

  • React-admin version: 3.2.1
  • React version: 16.13.0
  • Stack trace (in case of a JS error):
index.js:1437 Warning: Cannot update a component from inside the function body of a different component.
    in CheckboxGroupInput (at EditFormAlt.js:26)
    in FormDataConsumerView (created by FormDataConsumer)
    in FormDataConsumer (at EditFormAlt.js:23)
    in div (created by FormInput)
    in FormInput (created by SimpleFormView)
    in div (created by ForwardRef(CardContent))
    in ForwardRef(CardContent) (created by WithStyles(ForwardRef(CardContent)))
    in WithStyles(ForwardRef(CardContent)) (created by CardContentInner)
    in CardContentInner (created by SimpleFormView)
    in form (created by SimpleFormView)
    in SimpleFormView (created by FormView)
    in FormView (created by ReactFinalForm)
    in ReactFinalForm (created by FormWithRedirect)
    in FormWithRedirect (created by SimpleForm)
    in SimpleForm (at EditFormAlt.js:20)
@fzaninotto
Copy link
Member

Duplicate of #4572

@fzaninotto fzaninotto marked this as a duplicate of #4572 Mar 30, 2020
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