How do I build a dynamic dependent select form using react+redux, as we are receiving data from backend API?
We are receiving the data from the backend API to load up the same in our select form.
There going to be multiple dynamic dependent select fields in the form.
Once we select the value in the first field the second one loads up the data associated wit...
isubhokarma.hashnode.dev
You can use javascript's compute property capabilities. Let's say you want to dynamically select the district based on the state. Construct a json describing your conditions.
[ { "fieldName":"state", "dependentOn":null }, { "fieldName":"district", "dependentOn":"state" //this name should be same as that of mapStateToProps }, { "fieldName":"city", "dependentOn":"district" }, ]Iterate over the above to create react elements and for each you can access the values using selectors. ex:
const getDistrictsByState = (currentState) => { return (state)=>state[currentState] //computed at runtime }Hope this gives you some idea :)