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.

Confusing error "useStyles: `styles` is undefined" from a simple mistake

See original GitHub issue

Description

If you wrap a ListItem in anything other than OrderedList/UnorderedList, you get a confusing useStyles ContextError

Link to Reproduction

https://codesandbox.io/s/gracious-breeze-lwfur

Steps to reproduce

Shove a ListItem inside another element with an as=“ol”/as=“ul” and you get this error.

I’m sure there’s some logical reason why ListItem components must be children of OrderedList/UnorderedList components and it doesn’t work with a simple as on some other generic component like Box or Flex. But the error you get seems completely unrelated:

useStyles: `styles` is undefined. Seems you forgot to wrap the components in `<StylesProvider />` 

It makes you think “how does the rest of the app work then if StylesProvider isn’t set” so it’s certainly confusing and I’ve hit this twice recently (just enough time between both occurances for me to forget what the cause was!)

Chakra UI Version

1.7.0

Browser

Seems to be irrelevant to browsers, occurs in all

Operating System

  • macOS
  • Windows
  • Linux

Additional Information

Just a QoL thing, a better error that points to the actual cause and solution would be great, especially for newcomers to Chakra!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:6
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
jcleefwcommented, Jan 6, 2022

I seem to get the similar issue with Table … hmm wonder if the same trick will fix the issue

1reaction
LulaV14commented, May 20, 2022

@quangnmwork Seems like the error message is intended to say there was a parent tag missing. In my case I was getting this error message when trying to add a <TagLabel> without adding the proper parent tag <Tag>

So this works for me:

<Tag>
  <TagLabel>Example</TagLabel>
</Tag>
Read more comments on GitHub >

github_iconTop Results From Across the Web

React Typescript Material-UI useStyles not callable
you can solve it by importing from '@mui/styles' import { makeStyles, createStyles } from '@mui/styles';.
Read more >
Migration from v4 to v5 - MUI
To get the benefits of bug fixes and a lot of improvements such as the new styling engine. This documentation page covers the...
Read more >
Design Patterns with React Easy State | by Bertalan Miklos
React Easy State is a transparent reactive state management library with two functions and two accompanying rules. Always wrap your components with view()...
Read more >
A Guide to Common React Errors
The bug: You returned undefined, which is an invalid type for React's render method to return. ... The fix: Return a valid type:...
Read more >
Chapter 25: Troubleshooting Your Book - Jutoh
This chapter explains why you need to do this, what errors are likely to crop up ... paragraphs or objects that use styles...
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