zekchan / react-ssr-error-boundary

34 stars 14 forks source link

Support new Context API #4

Closed overlookmotel closed 5 years ago

overlookmotel commented 5 years ago

This PR is my first stab at a solution to #2, supporting React's new Context API which is what React Router etc use.

I've succeeded in making it automatic - you don't need to declare the contexts in use. But that comes at the cost of monkey-patching React's .createContext() method to record all contexts in use. To activate the shim which makes it work, you need to do require('react-ssr-error-boundary/server').shim().

Alternatively, contexts can be added manually with require('react-ssr-error-boundary/server').useContext().

It needs some tidying up and I'd intend to write more tests, but is this PR something you'd consider merging?