I'm trying to pass an argument to an axios post request
Normally what I need is this kind of JSON
[{"moduleId":"ASDJI-1212JSDF-12412SN"}]
This would come from clicking a value in a listbox and moving it to the right
I have this code where I push the value of the listbox to an array state
const [selectedModules, setSelectedModules] = useState([]);
const retrieveActionsList = useCallback(() => {
ProfileMaintenanceService.retrieveActionsList(selectedModules)
.then((response) => {
console.log("ProfileMaintenancePage - retrieveActionsList response.data >>> " + response.data)
console.log("ProfileMaintenancePage - retrieveActionsList JSON.stringify(response.data) >>> " + JSON.stringify(response.data))
setListboxActions(response.data);
}).catch((err) => {
console.log("ProfileMaintenancePage - retrieveActionsList catch >>> " + err)
})
});
const handleOnChange = (selected) => {
console.log("selected " + selected)
selectedModules.push(selected);
retrieveActionsList()
};
return (
<DualListBox
options={ newOptionsListbox }
selected={ selectedModules }
onChange={ handleOnChange }
showHeaderLabels={ true }
disabled={ disabled }
/>
)
Somehow, I'm getting this value:
[["C77C1031-2714-483D-AE59-21C9CD5EBAEF"]]
Would like to ask for help how to convert this to proper JSON format.
TIA
EDIT:
axios request
/* API for populating actions in listbox */
retrieveActionsList(selectedModules) {
return axios.post(`${API_URL_RETRIEVE_ACTIONS}`,
[
{
moduleId: selectedModules
}
]
)
}