Created
July 12, 2018 16:38
-
-
Save vabruzzo/c995165d148d46a70a7f584949a36d18 to your computer and use it in GitHub Desktop.
React safeRender HoC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # React `safeRender` higher-order component | |
| ## Common error | |
| attempting to access properties on `null` or `undefined` values causes internal server errors, breaks entire site | |
| ## Prior solutions | |
| 1. defensive programming using idioms like `object && object.value1 && object.value1.value2` and lodash's `prop(object, 'value1.value2')` | |
| 2. Ensure data validity and correctness in falcon, etc. | |
| Problem with 1: no errors are thrown, need to rely on humans in some cases to notice something wrong with frontend. | |
| Problem with 2: this is good approach, but it is a longer term project and guranteeing we catch all cases is difficult, to say the least. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment