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.

[useStyles] Prop passing after v5 migration

See original GitHub issue

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior 😯

We are trying to migrate from v4 to v5 and we use a lot of makeStyles and useStyles. We are trying to migrate the style component and apply the styled code mode, but many files are throwing errors. For example, we use useStyles for prop pass, but the code mod using useStyles was deleted, but props remained idle. And naturally the app doesn’t compile. image

Expected behavior 🤔

We don’t know how to use the props we give to useStyles when using styled-component. If we know what we can use instead of use useStyles, we can apply it.

Your environment 🌎

`npx @mui/envinfo`
 System:
    OS: Windows 10 10.0.19043
  Binaries:
    Node: 14.18.0 - C:\Program Files\nodejs\node.EXE        
    Yarn: 1.22.5 - C:\Program Files (x86)\Yarn\bin\yarn.CMD 
    npm: 6.14.15 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: Not Found
    Edge: Spartan (44.19041.1266.0), Chromium (96.0.1054.34)
  npmPackages:
    @emotion/react: ^11.6.0 => 11.6.0 
    @emotion/styled: ^11.6.0 => 11.6.0 
    @mui/base:  5.0.0-alpha.55 
    @mui/codemod: ^5.1.1 => 5.1.1 
    @mui/icons-material: ^5.1.1 => 5.1.1 
    @mui/lab: ^5.0.0-alpha.55 => 5.0.0-alpha.55 
    @mui/material: ^5.1.1 => 5.1.1 
    @mui/private-theming:  5.1.1 
    @mui/styled-engine:  5.1.1 
    @mui/styles: ^5.1.1 => 5.1.1 
    @mui/system: ^5.1.1 => 5.1.1 
    @mui/types: ^7.1.0 => 7.1.0 
    @mui/utils:  5.1.1 
    @types/react:  16.9.56 
    react: ^17.0.2 => 17.0.2 
    react-dom: ^17.0.2 => 17.0.2 
    styled-components:  3.4.10 
    typescript:  3.5.1

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
mnajdovacommented, Nov 29, 2021

@cengizcmataraci as far as I can see the API you are using is not correct. Check https://mui.com/styles/basics/#adapting-based-on-props

On the other hand, if you wish to adopt to v5, you can use styled() or sx prop, or migrate to tss-react for using an API similar to makeStyles. I hope this helps.

0reactions
cengizcmataracicommented, Nov 26, 2021

I also get the error “Transformation error (Unexpected token (168:2)) SyntaxError: Unexpected token (168:2)” when I refer to the styled code mode, and another 116 files also get an error.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[useStyles] Prop passing after v5 migration #29904 - GitHub
We are trying to migrate the style component and apply the styled code mode, but many files are throwing errors. For example, we...
Read more >
Breaking changes in v5, part one: styles and themes - MUI
This is a reference guide to all of the breaking changes introduced in Material v5, and how to handle them when migrating from...
Read more >
Passing props to MUI styles - reactjs - Stack Overflow
In MUI v5, this is how you access the props when creating the style object using styled() : import { styled } from...
Read more >
Material UI 5 - the easiest way to migrate from makeStyles to ...
We setup the ThemeProvider and StylesProvider in our root component; We create a custom hook useStyles; We get rid of the makeStyles and...
Read more >
makeStyles -> useStyles - Setup
const useStyles = makeStyles()({. //If you don't need neither the theme nor any state or. //props to describe your component style you can...
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