Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6214

pass a function to a custom react hook

$
0
0

Previously, I was using a graphql query like this. The data is returned from the query and I use setShowFlatListwith the datareturned:

  const [loadUsers, { data }] = useUsersLazyQuery({    onCompleted: () => {      setShowFlatList(data);    },});

Now I am creating a custom react hook where I use this graphql query. It looks like this:

export const useLoadUsers = (onCompleted: any) => {  const [usersQuery, { data }] = useUsersLazyQuery({    onCompleted: () => {      if(onCompleted){        onCompleted();      }    },    onError: onLoadUserError,    fetchPolicy: 'network-only',  });const loadUsers = async (phoneNumber: number,) => {  const data = await usersQuery({    variables: {      where: {        OR: [          { phoneNumber: newPhoneNumber }        ],      },    },    });  return data;};return loadUsers;};

But I cannot figure out how to pass the setShowFlatList function to the onCompleted of the hook, such that I can still use dataas its parameter from within the hook.


Viewing all articles
Browse latest Browse all 6214

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>