Skip to content

Instantly share code, notes, and snippets.

@vabruzzo
Created July 12, 2018 16:38
Show Gist options
  • Select an option

  • Save vabruzzo/c995165d148d46a70a7f584949a36d18 to your computer and use it in GitHub Desktop.

Select an option

Save vabruzzo/c995165d148d46a70a7f584949a36d18 to your computer and use it in GitHub Desktop.
React safeRender HoC
# 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