react-async-states
react-async-states copied to clipboard
enhance the read api support + suspense and error boundary
The read api should allow to specify whether to suspend on initial status, and also whether to throw on error status.
function read(suspendingStatuses, throwingStatuses) {
if (suspendingStatuses[currentState.status]) throw suspender; // promise
if (suspendingStatuses[currentState.status]) throw selector(currentState.data); // or may br throw state.data ? or even make it configurable ?
return selector(state, lastSuccess, cache);
}
const state = read({initial: true, pending: false}, {error: true, aborted: true });
// rules:
// no state should be truthy in both parameters
// doesn't care if you have suspense or error boundary up in the tree, if you suspend, you need suspense, if you throw on error, you need error boundary