Skip to content

Commit

Permalink
[docs] Access custom properties in the code without typescript error …
Browse files Browse the repository at this point in the history
…by extending theme type from @mui/system
  • Loading branch information
Digvijay Gupta authored and Digvijay Gupta committed Oct 1, 2023
1 parent ed315c5 commit 99ab22b
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions docs/data/system/getting-started/the-sx-prop/the-sx-prop.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,30 @@ export default function App() {
}
```

To fix and avoid typescript errors while accessing the custom properties from theme using `sx` prop callback, you can extend the `Theme` type from the `@mui/system` library:

```ts
declare module '@mui/system' {
interface Theme {
propertyKey: {
nestedPropertyKey: Type;
};
}
}

export default function App() {
return (
<Box
sx={(theme) => ({
bgcolor: theme.propertyKey.nestedPropertyKey,
})}
>
Example
</Box>
);
}
```

## Performance

To learn more about the performance tradeoffs of the `sx` prop, check out [Usage–Performance tradeoffs](/system/getting-started/usage/#performance-tradeoffs).

0 comments on commit 99ab22b

Please sign in to comment.