Skip to content

Commit

Permalink
[RNBS-016] - added some TypeScript extra features
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillzyusko committed May 9, 2020
1 parent f244eb6 commit 1e73b17
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/optimized.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ type State = {

const optimized = (screenName: string): any => {
class OptimizedComponent extends React.PureComponent<Props, State> {
component: React.ElementType | null = null;
placeholder: React.ElementType | null = mapLoadable[screenName].placeholder;
private component: React.ElementType | null = null;
private placeholder: React.ElementType | null = mapLoadable[screenName].placeholder;

constructor(props: Props) {
super(props);
Expand All @@ -27,7 +27,7 @@ const optimized = (screenName: string): any => {
};
}

componentDidMount() {
public componentDidMount(): void {
if (this.component === null) {
const { component } = getComponent(screenName);
this.component = component;
Expand All @@ -36,13 +36,13 @@ const optimized = (screenName: string): any => {
}
}

render() {
public render(): React.ReactNode {
const BundleComponent = this.component;
const Placeholder = this.placeholder;
const PlaceholderComponent = Placeholder ? <Placeholder /> : Placeholder;

return this.state.needsExpensive && BundleComponent ?
<BundleComponent {...this.props} /> : PlaceholderComponent;
<BundleComponent {...this.props} /> : PlaceholderComponent;
}
}

Expand Down

0 comments on commit 1e73b17

Please sign in to comment.