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.

[styles] custom theme variables with makeStyles

See original GitHub issue
  • This is not a v0.x issue.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior 🤔

makeStyles have access to custom variables created in theme https://material-ui.com/customization/themes/#custom-variables

Current Behavior 😯

makeStyles cannot access custom variables created in theme

const useStyles = makeStyles(theme => {
  console.log(theme); // no theme custom variables
  return {
    root: {
      width: '100%',
    },
  };
});

Steps to Reproduce 🕹

Link:

https://codesandbox.io/s/ovjn13pvk9

Your Environment 🌎

Tech Version
Material-UI v3.6.0
Material-UI/styles v3.0.0-alpha.1
React 16.7.0-alpha.2

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:6
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

10reactions
eps1loncommented, Nov 29, 2018

makeStyles is theme agnostic. You actually have to provide a theme via @material-ui/styles/ThemeProvider: https://codesandbox.io/s/zr1mjxxpq4

5reactions
PabloDinellacommented, Mar 15, 2019

Can’t find this ‘function as a parameter of makeStyles syntax’ in docs, I only see examples passing an object to makeStyles. Shouldn’t it be noted that makeStyles also accepts a function that will receive the theme, or is it noted somewhere else?

Read more comments on GitHub >

github_iconTop Results From Across the Web

[styles] custom theme variables with makeStyles · Issue #13734
Expected Behavior makeStyles have access to custom variables created in theme ... [styles] custom theme variables with makeStyles #13734.
Read more >
How to use 'theme' and 'props' in makeStyles? - Stack Overflow
makeStyles get the theme by params so you can create a styles.js for every component with a arrow function inside and calling from ......
Read more >
[Solved]-Using custom theme in makeStyles-Reactjs
Your custom theme is applied in this line: <ThemeProvider theme={theme}> , and your makeStyles function is called before that.
Read more >
Advanced (LEGACY) - MUI System
The makeStyles (hook generator) and withStyles (HOC) APIs allow the creation of multiple style rules per style sheet. Each style rule has its...
Read more >
Customize Theme - Ant Design
In version 5.0, we provide a new way to customize themes. Different from the less and CSS variables of the 4.x version, with...
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