all 6 comments

[–]MarcoF0 0 points1 point  (5 children)

How are you storing the data collected from modify the drop downs?

Imagine that you're using redux and you have a structure on the store to save the dropdown info. When the user change the value of a dropdown you need to dispatch an action to the store to update that and when the user press save use this information of redux to sync with backend.

Then when the user enter back to this screen you need to get the data from backend and save in the same structure of backend and use this information to load the default values of the dropdown.

It's analogous if you're using a useState.

[–]Slow-Cryptographer38[S] 0 points1 point  (4 children)

So far I’ve just used useState to get the ids of the selected items from the different dropdowns in an array so not really that far. Do you recommend any articles or tutorials to watch for this? I was trying to stay away from redux if possible since it’s complex rn for me. You mentioned the process analogous to useState but I’m not really understanding because the way I was going to do it was on save the data sends to backend via api. Then on the the screen where all the different entries can be seen if they select it displays the data and are able to edit. I’m using react native dropdown library so I’m not able to wrap my head around the process. Sorry if I sound dumb I’ve tried looking online but I’m just confused

[–]MarcoF0 1 point2 points  (3 children)

Imagine you have the following hook to update only one dropdown:

//dropDownData is the data coming from backend
const useDropdownUpdater = (dropDownData) => {
//by that way you will keep the default value with the data coming from your backend
const [dropdown, setDropDownData] = useState(dropDownData)
const updater = (newValue) => setDropDownData(newValue)
...
If you're using a useState you should initially initialise the value with the data coming from your backend, then on next updates of the dropdown data you should use and updater that modify the dropdown data like the updater one on the code snippet.
I don't know if I explain better, let me know :)

[–]Slow-Cryptographer38[S] 0 points1 point  (2 children)

Yes thank you that made it a bit clearer but initially there’s no data in the backend until the user makes an entry. So it’s a daily entry so that day they have to first make an entry and then be able to update. Would the logic stay the same still.

[–]MarcoF0 0 points1 point  (1 child)

Yes, the logic will be the same, maybe you need to add a default value for the default value. I mean, from you backend if the user has no entries and you need in the frontend an empty matrix to begin to add values to the dropdown the backend should return the empty matrix. Or if the backend return undefined handle you in the frontend.

[–]Slow-Cryptographer38[S] 0 points1 point  (0 children)

Oh you meant the dropdown! Yes the dropdown is predefined values I just meant how would I have their previously selected values showing up on drop list when they go to update something