react-async-component
react-async-component copied to clipboard
Add a method to retry resolution and pass it to error component
I use react-async-component for loading web pack modules with import() and find that they sometimes will timeout or otherwise fail to load.
I'd like to add a <Retry> button to my ErrorComponent but there wasn't a way to do so. This provides a function that could be called.
I've tested with simulated network timeout by putting Chrome offline and seems to work well.
I also added a spec and noticed a few things that could be improved there. Happy to rework if you spot anything else.
Codecov Report
Merging #70 into master will increase coverage by
2.42%. The diff coverage is100%.
@@ Coverage Diff @@
## master #70 +/- ##
=========================================
+ Coverage 94.38% 96.8% +2.42%
=========================================
Files 3 3
Lines 89 94 +5
Branches 25 25
=========================================
+ Hits 84 91 +7
+ Misses 5 3 -2
| Impacted Files | Coverage Δ | |
|---|---|---|
| src/asyncComponent.js | 96.05% <100%> (+3.09%) |
:arrow_up: |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing dataPowered by Codecov. Last update 94fc382...80c276a. Read the comment docs.
Any updates on this PR? I have the same problem (failed components will never resolve once networking is up again) and I would like to have this feature in the lib.
I implement this as an HOC wrapper around async, to retry with backoff: https://gist.github.com/mgreer/eb33c95d22cabcec22a26b28acacaa16 Happy to contribute this as an option in the lib too.