Skip to content

Failed to render with error "Rendered more hooks than during the previous render." #545

Closed Answered by Anxhul10
Anxhul10 asked this question in Q&A
Discussion options

You must be logged in to vote

The issue was not caused by Loki or the patch itself — it turned out to be related to how I structured the Storybook story when rendering multiple components that use React hooks internally.

Initially, I had the following story setup:

export const ManyItems: StoryFn<typeof Component> = () => (
  <>
    {Array.from({ length: 100 }).map((_, index) => (
      <HookUsingComponent key={index} propA={index} propB={index % 3 !== 0} />
    ))}
  </>
);

This caused the error:

Error: Rendered more hooks than during the previous render.

Solution

When I changed the logic to generate the component list before the return statement, and then used a variable to return them, the error was resolved:

expor…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Anxhul10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant