Search code examples
reactjsdependenciesdropdown

How to create dependency dropdown menu in react js


How we create dependency menu in react js . for ex: there are two dropdown menu named branch and subject respectively . In that I want if select branch from 1st dropdown then the subject of that branch only shown in 2nd dropdown .


Solution

  • You can do that by using condition. Simply use the following pattern set conditional rendering of component or data you want to display.

      {(branchOneClicked)?
        // Render your second branch
        :
        // else render something Else
        }
    

    Or, You can put a state with numbering. Let's say on branch clicked, change state and if that state === 1 (or the one you specified) render second one relating to it.

    PS: It'll be more helpful to give you answer if you provide us code. Thank you