MCPcopy
hub / github.com/obytes/react-native-template-obytes / AddPostScreen

Function AddPostScreen

src/features/feed/add-post-screen.tsx:22–105  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

20});
21
22export function AddPostScreen() {
23 const { mutate: addPost, isPending } = useAddPost();
24
25 const form = useForm({
26 defaultValues: {
27 title: '',
28 body: '',
29 },
30
31 validators: {
32 onChange: schema as any,
33 },
34 onSubmit: ({ value }) => {
35 console.log(value);
36 addPost(
37 { ...value, userId: 1 },
38 {
39 onSuccess: () => {
40 showMessage({
41 message: 'Post added successfully',
42 type: 'success',
43 });
44 // here you can navigate to the post list and refresh the list data
45 // queryClient.invalidateQueries(usePosts.getKey());
46 },
47 onError: () => {
48 showErrorMessage('Error adding post');
49 },
50 },
51 );
52 },
53 });
54
55 return (
56 <>
57 <Stack.Screen
58 options={{
59 title: 'Add Post',
60 headerBackTitle: 'Feed',
61 }}
62 />
63 <View className="flex-1 p-4">
64 <form.Field
65 name="title"
66 children={field => (
67 <Input
68 label="Title"
69 testID="title"
70 value={field.state.value}
71 onBlur={field.handleBlur}
72 onChangeText={field.handleChange}
73 error={getFieldError(field)}
74 />
75 )}
76 />
77 <form.Field
78 name="body"
79 children={field => (

Callers

nothing calls this directly

Calls 2

showErrorMessageFunction · 0.90
getFieldErrorFunction · 0.90

Tested by

no test coverage detected