Skip to content

How to dynamically change the component value based on the value of other component? #1066

Answered by rvsia
jessieweiyi asked this question in Need help
Discussion options

You must be logged in to vote

Hello,

in this case, I would create a new component or enhance the current select.

  1. Wrap it with FormSpy and set subscription={{values: true}} or set the form subscription for values. This ensures that the component will be always rendered when some value is changed.

  2. Use formOptions to get change function and use this function in useEffect hook when you need it.

I have this component implemented in one of my forms: https://github.com/RedHatInsights/sources-ui/blob/master/src/components/AddApplication/AuthTypeSetter.js It changes authentication value according to selectedAuthentication.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@jessieweiyi
Comment options

Answer selected by rvsia
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants