const [
MessageListDataProvider,
useMessageListData
] = constate(() => {
const [newValue, setNewValue] = useState({})
const [messagePath, useMessagePath] = useState(api.UNRESOLVED_MESSAGES_PATH)
const getMessagePath = (newPath) => {
useMessagePath(newPath)
}
const {
value,
loading,
error,
retry: refresh
} = useAsyncRetry(async () => {
return api.fetchAllMessages(messagePath)
}, [messagePath])
if (value !== undefined) {
console.log('value.messages', value.messages.length)
if (!newValue[messagePath]) {
console.log('newValue in conditional', newValue)
setNewValue(oldObj => ({ ...newValue, [messagePath] : value.messages }))
}
}
console.log('newValue', newValue)
return {
newValue,
getMessagePath,
value,
loading,
error,
refresh
}
})
I am trying to store specific values from an API call in a separate object based different keys.
example:
newValue : {
`/messages?limit=100&offset=0`: [{}, {}, {}],
`/messages?status=Unresolved&limit=100&offset=0`: [{}, {}, {}, {}, {}],
}
Strangely, the key gets updated and added but not the array value???!
See below...
Any idea how I can—for a lack of a better idea "catch" that API array value?