Skip to content

Commit

Permalink
Fix react native component stacks
Browse files Browse the repository at this point in the history
  • Loading branch information
main-- committed Feb 23, 2022
1 parent e7a1f85 commit 458e4bb
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/view.js
Expand Up @@ -29,11 +29,15 @@ export function view(Comp) {
Comp.prototype && Comp.prototype.isReactComponent
);

const compName = Comp.displayName || Comp.name;

let ReactiveComp;

// below, define both function and class component using the pattern { [name] ... }[name]
// in order to correctly set the function/class name in firefox backtraces
if (isStatelessComp && hasHooks) {
// use a hook based reactive wrapper when we can
ReactiveComp = props => {
ReactiveComp = { [compName](props) {
// use a dummy setState to update the component
const [, setState] = useState();
// create a memoized reactive wrapper of the original component (render)
Expand Down Expand Up @@ -63,12 +67,12 @@ export function view(Comp) {
} finally {
isInsideFunctionComponent = false;
}
};
} }[compName];
} else {
const BaseComp = isStatelessComp ? Component : Comp;
// a HOC which overwrites render, shouldComponentUpdate and componentWillUnmount
// it decides when to run the new reactive methods and when to proxy to the original methods
class ReactiveClassComp extends BaseComp {
const ReactiveClassComp = { [compName]: class extends BaseComp {
constructor(props, context) {
super(props, context);

Expand Down Expand Up @@ -140,12 +144,12 @@ export function view(Comp) {
// clean up memory used by Easy State
unobserve(this.render);
}
}
} }[compName];

ReactiveComp = ReactiveClassComp;
}

ReactiveComp.displayName = Comp.displayName || Comp.name;
ReactiveComp.displayName = compName;
// static props are inherited by class components,
// but have to be copied for function components
if (isStatelessComp) {
Expand Down

0 comments on commit 458e4bb

Please sign in to comment.