Skip to content
This repository was archived by the owner on Nov 27, 2022. It is now read-only.

Commit 6550653

Browse files
committed
fix: don't create a new component every time
1 parent 956f1f0 commit 6550653

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ renderScene = ({ route }) => {
223223

224224
Where `<HomeComponent />` is a `PureComponent`.
225225

226+
If you are using the `SceneMap` helper, the scenes are already optimized with `PureComponent` and won't re-render if parent's state changes.
226227

227228
### Avoid one frame delay
228229

src/SceneMap.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
import React, { PureComponent } from 'react';
44

55
export default function SceneMap(scenes: { [key: string]: Function }) {
6-
return ({ route }: *) => {
7-
class SceneComponent extends PureComponent {
8-
static displayName = `SceneMap(${route.key})`;
9-
10-
render() {
11-
return React.createElement(scenes[route.key], this.props);
12-
}
6+
class SceneComponent extends PureComponent<void, *, void> {
7+
render() {
8+
/* eslint-disable react/prop-types */
9+
return React.createElement(scenes[this.props.route.key], this.props);
1310
}
14-
return <SceneComponent key={route.key} route={route} />;
15-
};
11+
}
12+
13+
return ({ route }: *) => <SceneComponent key={route.key} route={route} />;
1614
}

0 commit comments

Comments
 (0)