I am running a graphql query inside my handleSubmit
that uses the name that user inputs and splits it into firstName
and lastName
. The behavior works perfectly with other where
inputs where I am using a single value and no splitted string.
Currently, I always get No User
, even if the user exists. The string splitting is also working correctly. I have verified that with logs.
const [name, setName] = useState(''); const [errorMessage, setErrorMessage] = useState(''); const showAlert = () => { Alert.alert('Friend Added'); } useEffect(() => { if (showAddFriendNamePage) return; setName(''); }, [showAddFriendNamePage]); const _onLoadUserError = React.useCallback((error: ApolloError) => { setErrorMessage(error.message); Alert.alert('Unable to Add Friend'); }, []); const getFriendId = React.useCallback( (data) => { console.log('name', name); if (data) { if (data.users.nodes.length == 0) { console.log('No user'); setErrorMessage('User Not Found'); Alert.alert('User Not Found'); } else { console.log('ID', data.users.nodes[0].id); //addFriend(Number(data.users.nodes[0].id)); } } }, [name, addFriend], ); const [loadUsers] = useUsersLazyQuery({ onCompleted: getFriendId, onError: _onLoadUserError, }); const handleSubmit = React.useCallback(() => { // let bothNames = name.split(""); console.log('Check name: ', (name.split(""))[0]); console.log('Check name: ', (name.split(""))[1]); console.log('Submitted'); loadUsers({ variables: { where: { firstName: (name.split(""))[0], AND: [{lastName:(name.split(""))[0]}]}, //where: { firstName: "MyName", AND: [{lastName:"Second"}]}, }, }); //setName(''); }, [loadUsers, name]);
<Input placeholder="Email" style={scaledAddFriendNameStyles.searchText} onChangeText={(text) => setName(text)} value={name} /><View ><Button onPress={() => handleSubmit()}> Add Friend{''}</Button>
I am using Safari's Develop tools to see the resources. In react, I was able to see the exact query running but in react native, I am unable to see the exact query. Instead, in the develop section, I get to see the whole bundle only.