When fetching data in the body of a functional component, the expression should evaluate either to a thrown promise or the response value, if I understand correctly. Does Suspense need the same promise to be thrown each time or just any promise? Is it doing anything with the promise ?
Asked
Active
Viewed 264 times
1
-
"fetching data" as in data that you will put in your component state, or do you mean that you are you fetching a module wrapped in suspense? You don't need to involve suspense if you are just fetching data to use as state, but you can use an [error boundary](https://reactjs.org/docs/code-splitting.html#error-boundaries) if you want to catch an error when loading a module. – Tholle Mar 16 '19 at 10:54
-
Not referring to loading a js module, but when fetching data from a backend api, using react-cache for example. ( https://codesandbox.io/s/6y0jpl802k ) – Stanley Johnson Mar 16 '19 at 11:36
-
Ah, I see. Then you don't need to worry about that the thrown error is of some particular type. The error boundary will catch all errors that were thrown in its child component tree. (https://codesandbox.io/s/jpy56l746y) – Tholle Mar 16 '19 at 11:41