I'm trying to use the sample code for an app bar provided in the documentation (note that I'm not using the AppBar component- I have my own header component. But I'm currently trying to create a SearchField component based on this code). I've basically cut and pasted the code as-is, and pulled out the parts not related to the search field. I'm getting an error: Uncaught TypeError: Cannot read property 'borderRadius' of undefined. Digging into it, I see that the theme object being passed into the function I pass into makeStyles is an empty object. I investigated further, to see if I could get my hands on the theme. When I export my component with withTheme()(searchBar), the theme object in the props is null. Likewise, if I just call useTheme() in my component, it also returns null.
Note: it seems the plain JS sample code (no hooks) works - so this has something to do with the Material-UI and React 16.8.0-alpha.1. However- this version is required to use the sample hooks code.
Expected Behavior 🤔
My makeStyles function should be passed the populated theme object, and withTheme and useTheme should return the proper non-null theme object.
Current Behavior 😯
The theme object passed into makeStyles is empty. The theme props attribute injected by withTheme is null. The theme object returned by useTheme is null.
Steps to Reproduce 🕹
Link: I don't have a live link but it's easy to reproduce:
- create-react-app testy
- cd testy
- Modify package.json, setting the react and react-dom versions to ^16.8.0-alpha.1 (to make use of hooks)
"react": "^16.8.0-alpha.1",
"react-dom": "^16.8.0-alpha.1",
- npm install (to update react)
- npm install --save @material-ui/core @material-ui/styles @material-ui/icons
- Copy the Hooks version of the Sample App Bar with a primary search field
- Paste this code into the test app's /src/App.js file (overwrite the existing code) and save
- npm start - you will get an undefined error when the makeStyles function accesses the empty theme object
Context 🔦
I'm trying to implement a toolbar in my app with Material-UI.
Your Environment 🌎
| Tech |
Version |
| Material-UI |
v3.9.2 |
| React |
16.8.0-alpha.1 |
| Browser |
Chrome 71.0 |
| TypeScript |
3.3.0-rc |
| etc. |
|
I'm trying to use the sample code for an app bar provided in the documentation (note that I'm not using the AppBar component- I have my own header component. But I'm currently trying to create a SearchField component based on this code). I've basically cut and pasted the code as-is, and pulled out the parts not related to the search field. I'm getting an error:
Uncaught TypeError: Cannot read property 'borderRadius' of undefined. Digging into it, I see that the theme object being passed into the function I pass into makeStyles is an empty object. I investigated further, to see if I could get my hands on the theme. When I export my component with withTheme()(searchBar), the theme object in the props is null. Likewise, if I just call useTheme() in my component, it also returns null.Note: it seems the plain JS sample code (no hooks) works - so this has something to do with the Material-UI and React 16.8.0-alpha.1. However- this version is required to use the sample hooks code.
Expected Behavior 🤔
My makeStyles function should be passed the populated theme object, and withTheme and useTheme should return the proper non-null theme object.
Current Behavior 😯
The theme object passed into makeStyles is empty. The theme props attribute injected by withTheme is null. The theme object returned by useTheme is null.
Steps to Reproduce 🕹
Link: I don't have a live link but it's easy to reproduce:
Context 🔦
I'm trying to implement a toolbar in my app with Material-UI.
Your Environment 🌎