StaticRenderer.js 769 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. * @format
  8. * @flow strict-local
  9. */
  10. 'use strict';
  11. const React = require('react');
  12. type Props = $ReadOnly<{|
  13. /**
  14. * Indicates whether the render function needs to be called again
  15. */
  16. shouldUpdate: boolean,
  17. /**
  18. * () => renderable
  19. * A function that returns a renderable component
  20. */
  21. render: () => React.Node,
  22. |}>;
  23. class StaticRenderer extends React.Component<Props> {
  24. shouldComponentUpdate(nextProps: Props): boolean {
  25. return nextProps.shouldUpdate;
  26. }
  27. render(): React.Node {
  28. return this.props.render();
  29. }
  30. }
  31. module.exports = StaticRenderer;