question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: useState is not a function or its return value is not iterable

See original GitHub issue

I’m rendering CollectionItem components inside CollectionsList component

There’re 4 main state variables in CollectionList component.

  1. rawCollections which holds all of the collections.
  2. allCollections which holds all of the collections in raw collections with filtering applied.
  3. collectionsToShow which holds the number of collections to load/show.
  4. loadedCollections which holds the loaded collections.

Everytime filtering is applied, allCollections is updated accordingly, which results in updating of loadedCollections.

loadedCollections is mapped to CollectionItem components which has their own state variable in them, defined by useState.

The problem:

Sometimes when filtering is applied, and loadedCollections is updated I get the following error inside one of the CollectionItem components:

TypeError: useState is not a function or its return value is not iterable

The line causing error inside CollectionItem:

const [currentPage, setCurrentPage] = useState(1);

I don’t see any apparent reason for this to happen, so what can that be?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
rschristiancommented, Dec 6, 2022

@daoanhthanh

  1. That’s not actually using Preact so you might’ve gotten a bit lost? React repo can be found here if you’re (still) having issues: https://github.com/facebook/react
  2. Hooks were introduced in React v16.8. That example is using 16.1.1. Update the React versions and you should be good to go!
0reactions
rschristiancommented, Nov 28, 2022

Certainly no worries! And I might be a tad biased, but Preact is a pretty neat React alternative that you might want to take a look at some day! We’d love to have you.

https://preactjs.com/

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError dispatcher.useState is not a function when using ...
There could be many reasons, and most are due to version incompatibilites or using a ^ in package.json : 1. Ensure react and...
Read more >
is not a function or its return value is not iterable in ReactJs ...
TypeError : react__WEBPACK_IMPORTED_MODULE_0_default is not a function or its return value is not iterable 1 | import useState from 'react'; ...
Read more >
useState is not defined ReferenceError in React [Solved]
The "Uncaught ReferenceError: useState is not defined" occurs when we use the useState hook in our code but forget to import it. To...
Read more >
is not a function or its return value is not iterable react - You.com
Firebase: snapshot.val is not a function or its return value is not iterable; I've got this error: Uncaught TypeError: e.lngLat is not a...
Read more >
react__webpack_imported_mod...
TypeError : react__WEBPACK_IMPORTED_MODULE_1___default is not a function or its return value is not iterable ... This is because useState is not the default...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found