15 ms·
You get an error if you try to call an ES6 class as a function (without 'new'). So just try to do that inside a try-catch. If there is no error you know it is
by galaxyLogic 8y ago
You get an error if you try to call an ES6 class as a function (without 'new'). So just try to do that inside a try-catch. If there is no error you know it is not a class and you have the result of the function already. If you do get an error and you know it is a function you know it must be a class.
- efrafa 8y agoClasses get transpiled to functions, but even if they wouldnt, what if function body throws?
- alangpierce 8y agoI believe throwing and catching exceptions over and over as part of normal rendering is the sort of thing that would be disastrous for performance, certainly the sort of thing that the React authors would really want to avoid.
- sorahn 8y agoThe new suspense api is based on throwing and catching promises as part of the render, so I don’t think its that.
- danabramov 8y agoSuspense only uses throwing when it's blocked on network. There is huge difference between doing this once every few seconds, and doing this thousands of times per second.
- seattle_spring 8y agoYikes. Definitely do not do this.
- danabramov 8y agoThat would unfortunately be too slow for production.