From 8c64e0868e520ae0330b7bfd25a90da042d4d19b Mon Sep 17 00:00:00 2001 From: Fabrizio Cucci Date: Wed, 15 Jan 2025 06:11:21 -0800 Subject: [PATCH] Migrate rn-tester/IntegrationTests/SimpleSnapshotTest.js to function components (#48700) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/48700 As per title. Changelog: [Internal] Reviewed By: rshest Differential Revision: D68152855 fbshipit-source-id: 121cb5dd65673121a021da12d10c7a7e118bd0dc --- .../IntegrationTests/SimpleSnapshotTest.js | 41 ++++++++----------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/packages/rn-tester/IntegrationTests/SimpleSnapshotTest.js b/packages/rn-tester/IntegrationTests/SimpleSnapshotTest.js index 347de5c815d..b26b540d590 100644 --- a/packages/rn-tester/IntegrationTests/SimpleSnapshotTest.js +++ b/packages/rn-tester/IntegrationTests/SimpleSnapshotTest.js @@ -10,32 +10,29 @@ 'use strict'; -const React = require('react'); -const ReactNative = require('react-native'); +import * as React from 'react'; +import {useEffect} from 'react'; +import {NativeModules, StyleSheet, View} from 'react-native'; -const {StyleSheet, View} = ReactNative; -const {TestModule} = ReactNative.NativeModules; +const {TestModule} = NativeModules; -class SimpleSnapshotTest extends React.Component<{...}> { - componentDidMount(): void { +function SimpleSnapshotTest(): React.Node { + const done = (success: boolean) => { + TestModule.markTestPassed(success); + }; + useEffect(() => { if (!TestModule.verifySnapshot) { throw new Error('TestModule.verifySnapshot not defined.'); } - requestAnimationFrame(() => TestModule.verifySnapshot(this.done)); - } + requestAnimationFrame(() => TestModule.verifySnapshot(done)); + }, []); - done: (success: boolean) => void = (success: boolean) => { - TestModule.markTestPassed(success); - }; - - render(): React.Node { - return ( - - - - - ); - } + return ( + + + + + ); } const styles = StyleSheet.create({ @@ -57,6 +54,4 @@ const styles = StyleSheet.create({ }, }); -SimpleSnapshotTest.displayName = 'SimpleSnapshotTest'; - -module.exports = SimpleSnapshotTest; +export default SimpleSnapshotTest;