L
L
lookingfor22020-10-18 16:39:27
React
lookingfor2, 2020-10-18 16:39:27

Why does it say that the hook is not in a functional component?

Here is the component

import React, {useState, useEffect, Fragment} from 'react';
const [OperationsList, setOperationsList] = useState([]);
import {apiGetOperationsLoan} from '../api/Api';
import TabBar from './TabBar.jsx';
import TabBarItem from './TabBarItem.jsx';


export default function App() {
    useEffect(() => {
        apiGetOperationsLoan()
            .then((response) => {
                setOperationsList(response.data);
            });
    })
    return (
        <Fragment>
            <div className="cabinet__history-title">
                <h1>
                    История операций
                </h1>
            </div>
            <TabBar>
                <TabBarItem label="Операции ">

                </TabBarItem>
                <TabBarItem label="Финансовые ">
                    <p>2</p>
                </TabBarItem>
                <TabBarItem label="Системные ">
                    <p>3</p>
                </TabBarItem>
                <TabBarItem label="Кредитный ">
                    <p>4</p>
                </TabBarItem>
            </TabBar>

        </Fragment>
    );
}
/* eslint-enable */


Here is the error
VM18001 react.development.js:1465 Uncaught Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in same app

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WbICHA, 2020-10-18
@lookingfor2

Because it's not in a functional component?

import React, {useState, useEffect, Fragment} from 'react';
const [OperationsList, setOperationsList] = useState([]); // ← ← ←
import {apiGetOperationsLoan} from '../api/Api';

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question