title: Apollo query not triggering useEffect
body: <p>I need a refetch on an Apollo query to trigger useEffect. I'm implementing a filter bar that filters by a date period and a text search. My search submit button triggers the refetch on the query, and the data returned is a dependency of my useEffect. When the data is returned, if the search fields are populated, the filter should run. This works the first time I run a search, but when I reset with my reset function, the reset is triggered and the query gets 200 in Chrome and shows the data in Chrome dev tools, but useEffect is not triggered. Why is this?</p>
  
  <pre><code>//React
  import React, {useState, useContext, useEffect, Fragment } from 'react'
  
  //extra React libraries
  
  //external libraries
  import { useQuery, useMutation } from '@apollo/react-hooks'
  
  //components
  import AccountsGrid from '../../containers/AccountsGrid/AccountsGrid'
  import SpinnerLoader from '../../components/SpinnerLoader/SpinnerLoader'
  
  //styles
  import styles from "./accounts.module.scss";
  
  //contexts
  import UserContext from '../../containers/contexts/UserContext/UserContext'
  import AccountContext from '../../containers/contexts/AccountContext/AccountContext'
  
  //constants
  import { 
    GET_PARENT_ACCOUNT, 
    SET_ACCOUNTS,
    SET_IS_ACTIVE,
    SET_ACCOUNTS_LIMIT,
    SET_ACCOUNTS_OFFSET,
    SET_ACCOUNTS_TOTAL,
    SET_ACCOUNTS_START_DATE,
    SET_ACCOUNTS_END_DATE,
  } from '../../containers/contexts/AccountContext/accountActionTypes'
  
  import { 
    GET_ACCOUNT_USERS,
    GET_ACCOUNTS,
    TOTAL_ACCOUNTS,
    } from '../../utils/constants/queries/accountQueries'
  
  import {
    UPDATE_ACCOUNT
  } from '../../utils/constants/mutations/accountMutations'
  import moment from 'moment';
  
  
  function Accounts(props) {
    const userContext = useContext(UserContext)
    const accountContext = useContext(AccountContext)
    const parentAccountID = userContext.userState.accountId
    const [parentAccountIDs, setParentAccountIDs] = useState(null)
    const [sortByField, setSortByField] = React.useState(null);
    const [sortByType, setSortByType] = React.useState(null);
    const [startDate, setStartDate] = React.useState(null);
    const [endDate, setEndDate] = React.useState(null);
    const [datesValid, setDatesValid] = React.useState(true);
    const [searchText, setSearchText] = React.useState("");
  
    const { 
      loading: loadingAccountUsers, 
      error: errorAccountUsers, 
      data: dataAccountUsers,
      refetch: refetchAccountUsers,
    } = useQuery(GET_ACCOUNT_USERS, {
        variables: {
          accountId: parentAccountID
        }
    })
  
    const { 
      loading: loadingAccounts, 
      error: errorAccounts, 
      data: dataAccounts,
      refetch: refetchAccounts
    } = useQuery(GET_ACCOUNTS, {
        variables: {
          parentIds: parentAccountIDs,
          offset: accountContext.accountState.data.accountsOffset,
          limit: accountContext.accountState.data.accountsLimit
        }
    })
  
    const { 
      loading: loadingAccountsTotal, 
      error: errorAccountsTotal, 
      data: dataAccountsTotal,
      refetch: refetchAccountsTotal
    } = useQuery(TOTAL_ACCOUNTS)
  
    const [
      updateAccount,
      { loading, error, data: updateAccountData }
    ] = useMutation(UPDATE_ACCOUNT);
  
    const setParentIDsHandler = (id) =&gt; {
      setParentAccountIDs(String(id))
    }
  
    const setOffset = (offset, limit) =&gt; {
      accountContext.accountDispatch({
        type: SET_ACCOUNTS_OFFSET, 
        payload: {
          offset: offset
        }
      })
  
      accountContext.accountDispatch({
        type: SET_ACCOUNTS_LIMIT,
        payload: {
          limit: limit
        }
      })
    }
  
    const deactivateUser = row =&gt; {
      updateAccount({
        variables: {
          account: {
            id: row.id,
            isActive: !row.isActive
          }
        }
        })
        accountContext.accountDispatch({type: SET_IS_ACTIVE, payload: row.id})
      }
  
    const handleRequestSort = (sortType, sortBy) =&gt; {
      sortRow(sortBy)
      setSortByType(sortType)
    }
  
    const sortRow = (sortBy) =&gt; {
      switch(sortBy) {
        case 'Contact':
          setSortByField('email')
          break
        case 'First Name':
          setSortByField('firstName')
          break
        case 'Last Name':
          setSortByField('lastName')
          break
        case 'Join Date':
          setSortByField('dateJoined')
          break
      }
    }
  
    const setDates = (dates) =&gt; {
      console.log("SETTING DATES", dates)
      if ("startDate" === Object.keys(dates)[0]) {
        setStartDate(dates.startDate)
      } else {
        setEndDate(dates.endDate)
      }
    }
  
    const checkDatesValid = () =&gt; {
      if (startDate &amp;&amp; endDate) {
        if (startDate &lt;= endDate) {
          return setDatesValid(true)
        }
      }
      return setDatesValid(false)
    }
  
    const clearDates = () =&gt; {
      console.log("CLEARING")
      setDatesValid(true)
      setStartDate(null)
      setEndDate(null)
      setSearchText(null)
      accountContext.accountDispatch({type: SET_ACCOUNTS_START_DATE, payload: {startDate: null}})
      accountContext.accountDispatch({type: SET_ACCOUNTS_END_DATE, payload: {endDate: null}})
      return setDatesValid(true)
    }
  
    const searchByChars = (text) =&gt; {
      console.log("SEARCH TEXT", text)
      setSearchText(text)
      resetAccounts()
    }
  
    const resetAccounts = () =&gt; {
      console.log("RESET ACCOUNTS TRIGGERED")
      refetchAccounts({
        variables: {
          parentIds: parentAccountIDs,
          offset: accountContext.accountState.data.accountsOffset,
          limit: accountContext.accountState.data.accountsLimit
        }
      })
  
      console.log("LOADING", loadingAccounts)
      console.log("ERROR", errorAccounts)
    }
  
    const filterText = (textRows) =&gt; {
      let newTextRows = []
      for (let row of textRows) {
          Object.entries(row['users'][0]).forEach(([key, val]) =&gt; {
            if (String(val).includes(String(searchText))) {
              if (!(newTextRows.includes(row))) {
                newTextRows.push(row)
              }
            }
          });
      }
      accountContext.accountDispatch({type: SET_ACCOUNTS, payload: {accounts: newTextRows}})
    }
  
    const filterDates = (dateRows) =&gt; {
      let newDateRows = []
      for (let row of dateRows) {
        if (datesValid) {
          const _date = moment(row.users[0]['dateJoined'])
          const sdate = moment(startDate)
          const edate = moment(endDate)
          if (_date.isBetween(sdate, edate, null, '[]')) {
            if (!(newDateRows.includes(row))) {
              newDateRows.push(row)
            }
          }
        }
      }
      accountContext.accountDispatch({type: SET_ACCOUNTS, payload: {accounts: newDateRows}})
    }
  
    useEffect(() =&gt; {
      if (sortByField &amp;&amp; sortByType) {
        const newRows = accountContext.accountState.data.accounts.sort((a, b) =&gt; {
          const compareA = a.users[0][sortByField]
          const compareB = b.users[0][sortByField]
          if (compareA || compareB) {
            if ("DESC" === sortByType) {
              let comparison = 0;
              if (compareA &gt; compareB) {
                comparison = 1;
              } else if (compareA &lt; compareB) {
                comparison = -1;
              }
              return comparison;
            } else {
              let comparison = 0;
              if (compareA &lt; compareB) {
                comparison = 1;
              } else if (compareA &gt; compareB) {
                comparison = -1;
              }
              return comparison;
            }
          }
        })
        accountContext.accountDispatch({type: SET_ACCOUNTS, payload: newRows})
      }
      if (dataAccountsTotal) {
        accountContext.accountDispatch({type: SET_ACCOUNTS_TOTAL, payload: dataAccountsTotal})
      }
      if (dataAccountUsers) {
        setParentIDsHandler(dataAccountUsers.accountUsers[0].account.id)
        accountContext.accountDispatch({type: GET_PARENT_ACCOUNT, payload: dataAccountUsers})
      }
      if (dataAccounts) {
          console.log("NEW DATA", searchText, startDate, endDate, datesValid)
          console.log("SEARCH TEXT", searchText)
          console.log("START DATE", startDate)
          console.log("END DATE", endDate)
          accountContext.accountDispatch({type: SET_ACCOUNTS, payload: dataAccounts})
          console.log("DATES VALID", datesValid)
          if (startDate 
              &amp;&amp; endDate &amp;&amp; datesValid) {
            console.log("FILTER BY DATES")
            filterDates(accountContext.accountState.data.accounts)
          }
          if (searchText) {
            filterText(dataAccounts)
          }
        }
    }, [
      loadingAccounts,
      dataAccounts,
      dataAccountsTotal,
      dataAccountUsers,
      parentAccountIDs,
      updateAccountData,
      sortByField,
      sortByType,
      searchText
    ])
  
    return (
      &lt;Fragment&gt;
        {
          accountContext.accountState.data.accounts &amp;&amp; 
          !loadingAccountUsers &amp;&amp;
          !errorAccountUsers &amp;&amp;
          !loadingAccounts &amp;&amp;
          !errorAccounts &amp;&amp;
          parentAccountIDs &amp;&amp;
          accountContext.accountState.data.accountUsers 
          ? &lt;AccountsGrid 
            setOffset={setOffset}
            currentStartDate={startDate}
            currentEndDate={endDate}
            searchText={searchByChars}
            datesValid={datesValid}
            resetAccounts={resetAccounts}
            setDates={setDates}
            clearDates={clearDates}
            deactivateUser={deactivateUser}
            handleRequestSort={handleRequestSort}
            accountRows={accountContext.accountState.data.accounts}
          /&gt; : &lt;SpinnerLoader /&gt;}
      &lt;/Fragment&gt;
    )
  }
  export default Accounts
  </code></pre>