MUI blog template example - DAV-1000/react-material GitHub Wiki
Created: 7/31/2025 16:56
Updated: 7/31/2025 17:02
Exported: 8/14/2025 11:13
Link: https://chatgpt.com/c/688b9235-0b74-8001-8c5c-a3bd92cf96f3
Give me an example of using the Material UI Blog template in React
Sure! Here's a working example of how to use the Material UI (MUI) Blog template in a React app. Material UI provides a Blog template as part of its official template gallery, and you can customize it as needed.
-
Set up your React app
npx create-react-app mui-blog cd mui-blog npm install @mui/material @emotion/react @emotion/styled @mui/icons-material
- Replace
App.js
with the Blog template code
Below is a simplified version of the MUI Blog template in one file (App.js
). For a more modular structure, you'd break it up into components.
import React from 'react';
import {
AppBar, Toolbar, Typography, CssBaseline, Container, Grid, Card, CardContent, CardMedia, Link, Box
} from '@mui/material';
const featuredPosts = [
{
title: 'Post One',
date: 'Jul 31',
description: 'This is a wider card with supporting text below.',
image: 'https://source.unsplash.com/random?tech',
},
{
title: 'Post Two',
date: 'Jul 30',
description: 'This is another card with supporting text.',
image: 'https://source.unsplash.com/random?nature',
},
];
function Header() {
return (
<AppBar position="static" color="default" elevation={0}>
<Toolbar>
<Typography variant="h6" color="inherit" noWrap>
My Blog
</Typography>
</Toolbar>
</AppBar>
);
}
function MainFeaturedPost() {
return (
<Box sx={{ bgcolor: 'grey.200', p: 6, mb: 4 }}>
<Typography variant="h3" gutterBottom>
Welcome to My Blog
</Typography>
<Typography variant="h6" paragraph>
Explore insightful articles on tech, development, and design.
</Typography>
</Box>
);
}
function FeaturedPost({ post }) {
return (
<Grid item xs={12} md={6}>
<Card sx={{ display: 'flex', flexDirection: 'column' }}>
<CardMedia
component="img"
image={post.image}
alt={post.title}
height="200"
/>
<CardContent>
<Typography component="h2" variant="h5">
{post.title}
</Typography>
<Typography variant="subtitle1" color="text.secondary">
{post.date}
</Typography>
<Typography variant="subtitle1" paragraph>
{post.description}
</Typography>
<Link href="#">Continue reading...</Link>
</CardContent>
</Card>
</Grid>
);
}
export default function App() {
return (
<>
<CssBaseline />
<Header />
<Container maxWidth="lg">
<MainFeaturedPost />
<Grid container spacing={4}>
{featuredPosts.map((post) => (
<FeaturedPost key={post.title} post={post} />
))}
</Grid>
</Container>
</>
);
}
This will render:
- A header bar with "My Blog"
- A main featured section with an intro
- Two blog post cards (you can add more by extending
featuredPosts
)
- You can modularize components like
Header
,FeaturedPost
, andMainFeaturedPost
into separate files. - To match the full template from MUI's site, you'd also add:
- Footer component
- Sidebar with recent posts or archives
- Routing with React Router if needed
Would you like a version with routing or Markdown post support?
My react app is in typescript
Great! If your React app is using TypeScript, here's how you can adapt the Material UI Blog template to work with TypeScript.
npx create-react-app mui-blog-ts --template typescript
cd mui-blog-ts
npm install @mui/material @emotion/react @emotion/styled @mui/icons-material
Here's a modular version of the Blog using TypeScript components.
import React from 'react';
import CssBaseline from '@mui/material/CssBaseline';
import Container from '@mui/material/Container';
import Grid from '@mui/material/Grid';
import Header from './components/Header';
import MainFeaturedPost from './components/MainFeaturedPost';
import FeaturedPost from './components/FeaturedPost';
const featuredPosts = [
{
title: 'Post One',
date: 'Jul 31',
description: 'This is a wider card with supporting text below.',
image: 'https://source.unsplash.com/random?tech',
},
{
title: 'Post Two',
date: 'Jul 30',
description: 'This is another card with supporting text.',
image: 'https://source.unsplash.com/random?nature',
},
];
function App() {
return (
<>
<CssBaseline />
<Header title="My Blog" />
<Container maxWidth="lg">
<MainFeaturedPost />
<Grid container spacing={4}>
{featuredPosts.map((post) => (
<FeaturedPost key={post.title} post={post} />
))}
</Grid>
</Container>
</>
);
}
export default App;
import React from 'react';
import AppBar from '@mui/material/AppBar';
import Toolbar from '@mui/material/Toolbar';
import Typography from '@mui/material/Typography';
interface HeaderProps {
title: string;
}
const Header: React.FC<HeaderProps> = ({ title }) => (
<AppBar position="static" color="default" elevation={0}>
<Toolbar>
<Typography variant="h6" color="inherit" noWrap>
{title}
</Typography>
</Toolbar>
</AppBar>
);
export default Header;
import React from 'react';
import { Box, Typography } from '@mui/material';
const MainFeaturedPost: React.FC = () => (
<Box sx={{ bgcolor: 'grey.200', p: 6, mb: 4 }}>
<Typography variant="h3" gutterBottom>
Welcome to My Blog
</Typography>
<Typography variant="h6" paragraph>
Explore insightful articles on tech, development, and design.
</Typography>
</Box>
);
export default MainFeaturedPost;
import React from 'react';
import {
Card,
CardContent,
CardMedia,
Grid,
Typography,
Link,
} from '@mui/material';
interface Post {
title: string;
date: string;
description: string;
image: string;
}
interface FeaturedPostProps {
post: Post;
}
const FeaturedPost: React.FC<FeaturedPostProps> = ({ post }) => (
<Grid item xs={12} md={6}>
<Card sx={{ display: 'flex', flexDirection: 'column' }}>
<CardMedia component="img" image={post.image} alt={post.title} height="200" />
<CardContent>
<Typography component="h2" variant="h5">
{post.title}
</Typography>
<Typography variant="subtitle1" color="text.secondary">
{post.date}
</Typography>
<Typography variant="subtitle1" paragraph>
{post.description}
</Typography>
<Link href="#">Continue reading...</Link>
</CardContent>
</Card>
</Grid>
);
export default FeaturedPost;
mui-blog-ts/
βββ src/
β βββ components/
β β βββ Header.tsx
β β βββ MainFeaturedPost.tsx
β β βββ FeaturedPost.tsx
β βββ App.tsx
β βββ index.tsx
- Strong typing for
post
objects. - Reusable, modular components.
- Easy to scale into a full blog (with routing, markdown, CMS, etc).
Let me know if youβd like to add:
- Routing with
react-router-dom
- Markdown rendering for blog content
- Blog posts fetched from an API or local
.md
files
The instructions in the blog readme.md are : 1. Copy these folders (blog and shared-theme) into your project 2. Make sure your project has the required dependencies: @mui/material, @mui/icons-material, @emotion/styled, @emotion/react, markdown-to-jsx. 3. Import and use the Blog component.
Thanks for the clarification! You're referring to the official Material UI Blog Template from the MUI GitHub repo, which is structured around two folders: blog/
and shared-theme/
.
Let's walk through how to integrate it in your TypeScript React app.
Go to the GitHub repository:
π MUI Blog Template on GitHub
Download or copy these two folders into your projectβs src/
directory:
src/
βββ blog/
βββ shared-theme/
Make sure the
*.js
or*.jsx
files are renamed to*.tsx
, and adjust types accordingly if needed.
npm install @mui/material @mui/icons-material @emotion/react @emotion/styled markdown-to-jsx
For TypeScript support (optional but recommended):
npm install --save-dev @types/react @types/react-dom
In the files inside blog/
and shared-theme/
, update any .js
or .jsx
extensions in imports to .tsx
or remove the extension if using modern module resolution.
Also, in some cases you'll want to add types like this:
// Example in blog/components/Main.tsx
const Main: React.FC<{ posts: Post[] }> = ({ posts }) => {
// ...
};
In your App.tsx
(or a route/page component), simply use:
import React from 'react';
import Blog from './blog/Blog'; // Adjust path if needed
function App() {
return <Blog />;
}
export default App;
src/
βββ App.tsx
βββ blog/
β βββ [all blog components like Blog.tsx, Main.tsx, Sidebar.tsx etc.]
βββ shared-theme/
β βββ [theme/index.ts, branding etc.]
- Convert all
.js
to.ts
or.tsx
with types. - Add typing for blog posts (
Post
interface). - Modularize content with Markdown files or an API later.
Would you like me to give you the full TypeScript version of the Blog.tsx
with all necessary types included?
Powered by ChatGPT Exporter