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.

How to use and override themes with hooks

See original GitHub issue

Hey!

I’m struggling in properly using and overriding themes. I want to use the default theme with some custom overrides (e.g. different font size).

Example: https://codesandbox.io/s/j7owzjlnqv

    "react": "16.8.0-alpha.1",
    "react-dom": "16.8.0-alpha.1",
    "react-scripts": "2.1.3",
    "@material-ui/core": "3.9.0",
    "@material-ui/styles": "^3.0.0-alpha.8"

With typescript, I cannot seem to use createMuiTheme from @material-ui/core/styles as importing it gives a conflict between jss@9 and jss@10 (latter is used by @material-ui/styles)

Thanks!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:14 (11 by maintainers)

github_iconTop GitHub Comments

4reactions
eps1loncommented, Jan 17, 2019

This is a common confusion. ThemeProvider is a generic theme provider. It does not automatically include the material-ui theme. You have to explicitly use it:

import { Typography } from "@material-ui/core";
import { createMuiTheme } from "@material-ui/core/styles";
import { ThemeProvider } from "@material-ui/styles";

function App() {
  const theme = createMuiTheme({
    typography: { body1: { fontSize: "2rem" } }
  });
  return (
    <ThemeProvider theme={theme}>
      <Typography variant="body1">Hey</Typography>
    </ThemeProvider>
  );
}
2reactions
eps1loncommented, Jan 30, 2019

~@skoging Seems like you posted in the wrong issue. This is basically what I outlined in https://github.com/mui-org/material-ui/issues/14297#issuecomment-458508064~

The issue with typescript and conflicting jss types is continued in #14297. Usage issue seems resolved with https://github.com/mui-org/material-ui/issues/14217#issuecomment-455174494

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use and override themes with hooks #14217 - GitHub
Hey! I'm struggling in properly using and overriding themes. I want to use the default theme with some custom overrides (e.g. different font ......
Read more >
How to use hooks in child theme to override a plugin?
1 Answer 1 ... you can't really override a function like that. you can only use the filters and hooks that the plugin...
Read more >
A Guide to Overriding Parent Theme Functions in Your Child ...
In this tutorial, I'll show you three methods you can use to override functions from the parent theme in your child theme:.
Read more >
Override Plugin Function with Hooks - WordPress.org
I have a function that I need to override to change the translation. I can't just translate it through strings with WPML of...
Read more >
Allow theme hooks to override module hooks [#3178013]
When using the preprocess module, the hook within the src/Plugins/Preprocess fires *after* the hook in the theme is processed.
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