Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

makeStyles always requires props #16867

Closed
2 tasks done
Cretezy opened this issue Aug 2, 2019 · 11 comments
Closed
2 tasks done

makeStyles always requires props #16867

Cretezy opened this issue Aug 2, 2019 · 11 comments

Comments

@Cretezy
Copy link

Cretezy commented Aug 2, 2019

makeStyles which does not use props should not require props

  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

const useStyles = makeStyles({
  root: {
    backgroundColor: "white"
  }
});

export default function Home() {
  const classes = useStyles();
  return <div className={classes.root} />;
}

Expected 1 arguments, but got 0. An argument for 'props' was not provided for the useStyles class.

Expected Behavior 🤔

makeStyles which does not use props should not require props

Steps to Reproduce 🕹

https://codesandbox.io/s/create-react-app-with-typescript-6wuym?fontsize=14

See above code.

Oddly enough, the codesandbox does not show the error

Context 🔦

Trying to use makeStyles with no props. I current have to pass {} to bypass this issue.

Your Environment 🌎

Tech Version
Material-UI v4.3.0
React v16.8.6
TypeScript 3.5.3
@merceyz
Copy link
Member

merceyz commented Aug 2, 2019

Guessing you have strictNullChecks set to false which isn't supported.
See https://material-ui.com/guides/typescript/

@Cretezy
Copy link
Author

Cretezy commented Aug 2, 2019

We're not using strictNullChecks, this is our tsconfig.json:

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": false,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "jsx": "preserve",
    "isolatedModules": true
  },
  "exclude": ["node_modules"],
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"]
}

@merceyz
Copy link
Member

merceyz commented Aug 3, 2019

You are because "strict": false sets strictNullChecks to false. (See https://www.typescriptlang.org/docs/handbook/compiler-options.html)
To fix the issue, set strict to true.

@eps1lon
Copy link
Member

eps1lon commented Aug 5, 2019

As @merceyz pointed out we're not supporting strictNullChecks: false.

Calling it with useMyStyles({}) would be equivalent.

@MarkMurphy
Copy link

I still seem to be having this issue using a fresh cra install. "strict": true is the default.

@eps1lon
Copy link
Member

eps1lon commented Sep 18, 2019

@MarkMurphy Please open a new issue and fill out the issue template.

@mchelen
Copy link

mchelen commented Oct 17, 2019

@MarkMurphy did you open a new issue? same issue here with fresh CRA and "strict": true

@Phebonacci
Copy link

Also experiencing the same issue. What's weird is only one component is showing the error. The others don't. I'm so confused

@knoefel
Copy link

knoefel commented Feb 15, 2021

@Phebonacci I had the same problem, all components worked, only one had the above error. I found this Answer, which said, that the createStyles function call is not necessary anymore. So i deleted it and just returned the style object from the makeStyles function call. Then the error disappeared.

@chrisk8er
Copy link

@Phebonacci I had the same problem, all components worked, only one had the above error. I found this Answer, which said, that the createStyles function call is not necessary anymore. So i deleted it and just returned the style object from the makeStyles function call. Then the error disappeared.

Thanks @knoefel you save my day...

@scrodrig
Copy link

scrodrig commented May 8, 2021

@knoefel that solved, tks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants