title: React native - Error: Hooks can only be called inside of a function component
body: <p>I have the following problem in my component &quot;SubmitButton&quot; I want to execute a custom hook by clicking on the button. This hook is called &quot;useLogin&quot;.</p>
  <p>But currently I always get the following error message: &quot;Invalid hook call. Hooks can only be called inside of the body of a function component.&quot;</p>
  <p>Can anyone tell me where my error is or what I am not understanding correctly?</p>
  <p>SubmitButton Code:</p>
  <pre><code>import React from &quot;react&quot;;
  import { View, Text, TouchableOpacity, StyleSheet } from &quot;react-native&quot;;
  import useLogin from &quot;../../../../app/hooks/useLogin&quot;;
  
  import { useSelector } from &quot;react-redux&quot;;
  
  const SubmitButton = () =&gt; {
  
    const email = useSelector((state) =&gt; state.login.email);
    const password = useSelector((state) =&gt; state.login.password);
  
    return (
      &lt;View&gt;
        &lt;TouchableOpacity
          style={styles.button}
          onPress={() =&gt; useLogin({ email, password })}
        &gt;
          &lt;Text style={styles.text}&gt;Anmelden&lt;/Text&gt;
        &lt;/TouchableOpacity&gt;
      &lt;/View&gt;
    );
  };
  
  </code></pre>
  <p>useLogin Code:</p>
  <pre><code>import api from &quot;../api/config&quot;;
  import { useEffect } from &quot;react&quot;;
  import { useDispatch } from &quot;react-redux&quot;;
  import * as SecureStore from &quot;expo-secure-store&quot;;
  import { setJwtToken } from &quot;../redux/features/auth/loginSlice&quot;;
  
  export default function useLogin ({email, password}) {
    const dispatch = useDispatch();
  
    useEffect(() =&gt; {
      login({email, password});
    }, []);  
  
    const login = async ({ email, password }) =&gt; {
      try {
        const response = await api.post(&quot;/users/login&quot;, { email, password });
        if (response.status === 200) {
          dispatch(setJwtToken(response.data.token));
          await SecureStore.setItemAsync(&quot;jwtToken&quot;, response.data.token);
        }
      }
      catch(e) {
        console.log(e);
      }
    };
  }
  
  
  </code></pre>