The main difference between this and the non-TypeScript example is that you need to add the following path config to your tsconfig.json
:
"paths": {
"@mui/styled-engine": ["./node_modules/@mui/styled-engine-sc"]
}
and install @types/styled-components:
npm install --save-dev @types/styled-components
Alternatively, to skip this configuration, you can set skipLibCheck: true
in your tsconfig.
Download the example or clone the repo:
curl https://codeload.github.com/mui/material-ui/tar.gz/master | tar -xz --strip=2 material-ui-master/examples/material-ui-cra-styled-components-ts
cd material-ui-cra-styled-components-ts
Install it and run:
npm install
npm start
Note that CodeSandbox is not supporting react-app-rewired, yet you can still see the code.
The following link leverages this demo: https://mui.com/material-ui/integrations/interoperability/#change-the-default-styled-engine with Parcel's alias feature within the package.json
.
This example demonstrates how to set up Material UI with Create React App with styled-components as a style engine for your application using TypeScript.
Note, the version 5 of @mui/styled-engine-sc
is compatible with version 5 of styled-components
, while the version 6 of @mui/styled-engine-sc
(currently in alpha), is compatible with v6 of styled-components
. When incorporating these dependencies into your project, consider this compatibility requirement. In this example application, both libraries are using version 6.
You now have a working example project. You can head back to the documentation and continue by browsing the templates section.