As per this sandbox: https://codesandbox.io/s/angry-bird-v2xy8 .
Clicking on the Product SOW checkbox will show 4 x components. These 4 x instances have been generated from code in the following location: ‘src’ - ‘components’ - ‘ExtendedOptionsTwo’ - ‘ProductSOW’.
The ‘ProductSOW.js’ file details the first step in a chain of files used to generate the 4 instances above.
Having successfully generated these reusable components (i’m not sure if I’ve done it the best way but it seems to work??) i now need to set up actions and reducers to update the store whenever any of the drop-down options (as per each instance) are chosen.
I currently have 1 x action (‘sendProdSelectionToRedux’) and 1 x reducer (‘sendProdSelectionToRedux’) to update the store with the first drop-down option picked.
If I click the checkbox under any image, choose a drop-down option then click the next checkbox under the next image (onBlur was used to update the store) I will see (In Redux Dev tools) that the store/state key: configOption is updated with the selection I just chose.
This is great but not quite what i’m after, because if I then choose another drop-down option this choice will overwrite the first choice.
What I need is for every drop-down selection to be added to the store (into an array of objects (componentInstanceName: dropDownOptionSelected)) then for that array of objects to be available when I submit the form.
As the component instances to access these drop downs are generated dynamically (via map and a reference to an array of objects in ‘ProductOptionsList)’ I don’t know how to configure the action and reducer to add each choice made from any drop-down into an array of configOption choices (and make it clear which instance the dropdown option came from).
Would I need multiple reducers/actions for this, if i need to make them dynamic, how would I do this?
I would be grateful if someone could please help me out?
- Have I misunderstood reusable components so therefore have made this situation a lot more complicated than i need to?
- If the setup is ok, how do i structure the actions and reducers?
======================
Actual result: the store key: ‘configOption’ is overwritten every time a dropdown option (in one of the component instances is chosen (this can be seen in redux dev tools when running the project in chrome)
Required result: a store key that is an array of objects (the number of objects depending on the number of options picked):
selectedConfigOptions = [
{componentInstanceName: dropDownOptionSelected},
{componentInstanceName: dropDownOptionSelected},
{componentInstanceName: dropDownOptionSelected}
]
The github for this sandbox is: https://github.com/char502/PDF-Gen-Redux-Two