FG
๐ŸŒ Web & Full-Stack

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:

Freshalmost 7 years ago
Mar 14, 20260 views
Confidence Score77%
77%

Problem

Hi all, I am new to react and I am trying to create a react library of components and I came across this problem because one of the components I am creating uses REACT HOOKS. Disclaimer: this is my first time creating an issue, so please bear with me. So I am trying to create an accordion component which toggles between these classes [code block] and [code block] to open and close. package.json [code block] webpack.config.js [code block] This is the accordion container: [code block] This is the accordion item that will live inside the container: [code block] Now inside of a create-react-app I import these components My library and the create-react-app are relative to each other and I am using [code block] [code block] I have followed all of these instructions and I still get the same error. Current behavior? [code block] Steps to reproduce - clone https://github.com/sethandleah/react-lib - clone https://github.com/sethandleah/myapp - [code block] - [code block] - [code block] - [code block] - [code block] - [code block] - [code block] Expected behavior - It should show a button with a "plus" svg sign and the words "Hello" and "World" respectively - Open devtools and go to elements - When clicking on the button the class [code block] should toggle To see the above, do the following: - Uncomment these lines at [code block] [code block] - The comment out these line, alse at [code block]: [code block] Versions of React, Browser / OS are affected by this

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
High Confidence Fix
74% confidence92% success rate9 verificationsLast verified Mar 14, 2026

Solution: 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:

Low Risk

>My library and the create-react-app are relative to each other and I am using npm link Did you read this part? https://reactjs.org/warnings/invalid-hook-call-warning.html#duplicate-react It directly addresses the `link` workflow: <img width="677" alt="Screen Shot 2019-04-04 at 09 28 47" src="https://user-images.githubusercontent.com/810438/55541034-118ffc00-56bc-11e9-9cc0-f04c0f7c3260.png">

74

Trust Score

9 verifications

92% success
  1. 1

    >My library and the create-react-app are relative to each other and I am using n

    >My library and the create-react-app are relative to each other and I am using npm link

  2. 2

    https://reactjs.org/warnings/invalid-hook-call-warning.html#duplicate-react

    https://reactjs.org/warnings/invalid-hook-call-warning.html#duplicate-react

  3. 3

    It directly addresses the `link` workflow:

    It directly addresses the `link` workflow:

  4. 4

    <img width="677" alt="Screen Shot 2019-04-04 at 09 28 47" src="https://user-imag

    <img width="677" alt="Screen Shot 2019-04-04 at 09 28 47" src="https://user-images.githubusercontent.com/810438/55541034-118ffc00-56bc-11e9-9cc0-f04c0f7c3260.png">

Validation

Resolved in facebook/react GitHub issue #15315. Community reactions: 144 upvotes.

Verification Summary

Worked: 9
Partial: 2
Failed: 1
Last verified Mar 14, 2026

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

reactjavascripttype:-needs-investigation