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 } })Estoy tratando de almacenar valores específicos de una llamada API en un objeto separado basado en diferentes claves.
ejemplo:
newValue : { `/messages?limit=100&offset=0`: [{}, {}, {}], `/messages?status=Unresolved&limit=100&offset=0`: [{}, {}, {}, {}, {}], }Extrañamente, la clave se actualiza y se agrega, pero no el valor de la matriz.
Vea abajo...
¿Alguna idea de cómo puedo, por falta de una mejor idea, "atrapar" ese valor de matriz API?