Skip to content

Commit a41e080

Browse files
authored
Merge pull request #127 from reduxjs/feature/redux-essentials-app-structure
Add TS counter template for the "Essentials" tutorial
2 parents 4fcc178 + 50ddf60 commit a41e080

File tree

22 files changed

+3634
-0
lines changed

22 files changed

+3634
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
dist
12+
dist-ssr
13+
*.local
14+
15+
# Editor directories and files
16+
.vscode/*
17+
!.vscode/extensions.json
18+
.idea
19+
.DS_Store
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?
25+
26+
typesversions
27+
.cache
28+
.yarnrc
29+
.yarn/*
30+
!.yarn/patches
31+
!.yarn/releases
32+
!.yarn/plugins
33+
!.yarn/sdks
34+
!.yarn/versions
35+
.pnp.*
36+
*.tgz
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"semi": false,
3+
"arrowParens": "avoid"
4+
}

packages/rtk-app-structure-example/.yarn/releases/yarn-4.2.2.cjs

Lines changed: 894 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
yarnPath: .yarn/releases/yarn-4.2.2.cjs
2+
3+
enableGlobalCache: false
4+
5+
nodeLinker: node-modules
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Redux Toolkit App Structure Example
2+
3+
This slimmed-down version of [the Redux Toolkit template for Vite](https://github.com/reduxjs/redux-templates/tree/master/packages/vite-template-redux) shows the standard app structure and store setup for Redux Toolkit, TypeScript, and React.
4+
5+
It's used in the ["Redux Essentials" tutorial Part 2](https://redux.js.org/tutorials/essentials/part-2-app-structure) as an embeddable CodeSandbox to help teach Redux app structure.
6+
7+
## Scripts
8+
9+
- `dev`/`start` - start dev server and open browser
10+
- `build` - build for production
11+
- `preview` - locally preview production build
12+
13+
## Inspiration
14+
15+
- [Create React App](https://github.com/facebook/create-react-app/tree/main/packages/cra-template)
16+
- [Vite](https://github.com/vitejs/vite/tree/main/packages/create-vite/template-react)
17+
- [Vitest](https://github.com/vitest-dev/vitest/tree/main/examples/react-testing-lib)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>React Redux App</title>
8+
</head>
9+
<body>
10+
<noscript>You need to enable JavaScript to run this app.</noscript>
11+
<div id="root"></div>
12+
<script type="module" src="/src/main.tsx"></script>
13+
</body>
14+
</html>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "rtk-app-structure-example",
3+
"private": true,
4+
"version": "0.0.0",
5+
"scripts": {
6+
"dev": "vite",
7+
"start": "vite",
8+
"build": "tsc && vite build",
9+
"type-check": "tsc --noEmit"
10+
},
11+
"dependencies": {
12+
"@reduxjs/toolkit": "^2.2.5",
13+
"react": "^18.2.0",
14+
"react-dom": "^18.2.0",
15+
"react-redux": "^9.1.0"
16+
},
17+
"devDependencies": {
18+
"@types/node": "^20.14.10",
19+
"@types/react": "^18.2.47",
20+
"@types/react-dom": "^18.2.18",
21+
"@vitejs/plugin-react": "^4.2.1",
22+
"prettier": "^3.2.1",
23+
"typescript": "^5.3.3",
24+
"vite": "^5.0.11"
25+
}
26+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
.App {
2+
text-align: center;
3+
}
4+
5+
.App-logo {
6+
height: 20vmin;
7+
pointer-events: none;
8+
}
9+
10+
@media (prefers-reduced-motion: no-preference) {
11+
.App-logo {
12+
animation: App-logo-float infinite 3s ease-in-out;
13+
}
14+
}
15+
16+
.App-header {
17+
min-height: 100vh;
18+
display: flex;
19+
flex-direction: column;
20+
align-items: center;
21+
justify-content: flex-start;
22+
font-size: calc(10px + 2vmin);
23+
}
24+
25+
.App-link {
26+
color: rgb(112, 76, 182);
27+
}
28+
29+
@keyframes App-logo-float {
30+
0% {
31+
transform: translateY(0);
32+
}
33+
50% {
34+
transform: translateY(10px);
35+
}
36+
100% {
37+
transform: translateY(0px);
38+
}
39+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import "./App.css"
2+
import { Counter } from "./features/counter/Counter"
3+
import logo from "./logo.svg"
4+
5+
const App = () => {
6+
return (
7+
<div className="App">
8+
<header className="App-header">
9+
<img src={logo} className="App-logo" alt="logo" />
10+
<Counter />
11+
<p>
12+
Edit <code>src/App.tsx</code> and save to reload.
13+
</p>
14+
<span>
15+
<span>Learn </span>
16+
<a
17+
className="App-link"
18+
href="https://reactjs.org"
19+
target="_blank"
20+
rel="noopener noreferrer"
21+
>
22+
React
23+
</a>
24+
<span> and </span>
25+
<a
26+
className="App-link"
27+
href="https://redux.js.org/tutorials/essentials/part-2-app-structure"
28+
target="_blank"
29+
rel="noopener noreferrer"
30+
>
31+
Redux
32+
</a>
33+
</span>
34+
</header>
35+
</div>
36+
)
37+
}
38+
39+
export default App
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// This file serves as a central hub for re-exporting pre-typed Redux hooks.
2+
import { useDispatch, useSelector } from "react-redux"
3+
import type { AppDispatch, RootState } from "./store"
4+
5+
// Use throughout your app instead of plain `useDispatch` and `useSelector`
6+
export const useAppDispatch = useDispatch.withTypes<AppDispatch>()
7+
export const useAppSelector = useSelector.withTypes<RootState>()

0 commit comments

Comments
 (0)