mirror of
https://github.com/status-im/react-native.git
synced 2025-02-23 14:48:25 +00:00
Summary: related #21342 The `render` function, I was not able to specifically type since the props passed to it may vary. At the moment only `renderRow` function from ListView component is using StaticRenderer, and the type of the renderRow function is `Function`. Let me know what your thoughts are on this. Thank you Pull Request resolved: https://github.com/facebook/react-native/pull/21348 Differential Revision: D10084990 Pulled By: TheSavior fbshipit-source-id: a87a8d4976c6ffaf83dc0fddc758869dbc2e2803
38 lines
756 B
JavaScript
38 lines
756 B
JavaScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
* @flow
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
const React = require('React');
|
|
|
|
type Props = $ReadOnly<{|
|
|
/**
|
|
* Indicates whether the render function needs to be called again
|
|
*/
|
|
shouldUpdate: boolean,
|
|
/**
|
|
* () => renderable
|
|
* A function that returns a renderable component
|
|
*/
|
|
render: () => React.Node,
|
|
|}>;
|
|
|
|
class StaticRenderer extends React.Component<Props> {
|
|
shouldComponentUpdate(nextProps: Props): boolean {
|
|
return nextProps.shouldUpdate;
|
|
}
|
|
|
|
render(): React.Node {
|
|
return this.props.render();
|
|
}
|
|
}
|
|
|
|
module.exports = StaticRenderer;
|