Skip to content

Commit f945ff5

Browse files
refactor: export onPress functions to methods
1 parent eab1887 commit f945ff5

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

examples/default/src/screens/SurveysScreen.tsx

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,22 @@ export const SurveysScreen: React.FC = () => {
3535
alignItems: 'stretch',
3636
},
3737
});
38+
39+
const checkIfUserHasResponded = async () => {
40+
if (validateUserAttributeForm()) {
41+
const hasResponded = await Surveys.hasRespondedToSurvey(surveyToken);
42+
toast.show({
43+
description: hasResponded ? 'YES' : 'NO',
44+
});
45+
}
46+
};
47+
48+
const showSurveyWithToken = () => {
49+
if (validateUserAttributeForm()) {
50+
Surveys.showSurvey(surveyToken);
51+
}
52+
};
53+
3854
return (
3955
<Screen>
4056
<ListTile
@@ -61,26 +77,11 @@ export const SurveysScreen: React.FC = () => {
6177
</View>
6278
</View>
6379

64-
<Button
65-
mt="4"
66-
onPress={() => {
67-
if (validateUserAttributeForm()) {
68-
Surveys.showSurvey(surveyToken);
69-
}
70-
}}>
80+
<Button mt="4" onPress={showSurveyWithToken}>
7181
Show survey
7282
</Button>
7383

74-
<Button
75-
mt="4"
76-
onPress={async () => {
77-
if (validateUserAttributeForm()) {
78-
const hasResponded = await Surveys.hasRespondedToSurvey(surveyToken);
79-
toast.show({
80-
description: hasResponded ? 'YES' : 'NO',
81-
});
82-
}
83-
}}>
84+
<Button mt="4" onPress={checkIfUserHasResponded}>
8485
If User has responded survey
8586
</Button>
8687
</VStack>

0 commit comments

Comments
 (0)