Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ jspm_packages
temp/
playground/dist
playground/storybook-static

CLAUDE.md
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,29 @@ _Found it useful? Want more updates?_
- Make type annotations concise by eliminating redundancy in types using advanced TypeScript Language features like **Type Inference** and **Control flow analysis**
- Reduce repetition and complexity of types with TypeScript focused [complementary libraries](#react-redux-typescript-ecosystem)

### **What This Guide Is**

This repository is a reference guide and recipe collection for using React, Redux, and TypeScript together. It is **not** a boilerplate, starter kit, or library that introduces its own replacement APIs for React.

Most of the types shown in this guide come from the official React and React Redux type packages such as `@types/react` and `@types/react-redux`. When you see names like `React.FC`, `React.ComponentType`, or `React.ReactNode`, they are existing React types that this guide explains and uses in examples.

### **How to Use This Guide**

If you are new to React, read this guide in the following order:

1. Start with the [Playground Project](#playground-project) to see where the examples live.
2. Read the [React Types Cheatsheet](#react-types-cheatsheet) before diving into the component recipes.
3. Work through the [React](#react) section from top to bottom, then move on to [Redux](#redux).
4. Use later sections like [Configuration & Dev Tools](#configuration--dev-tools) and [FAQ](#faq) as reference material when you need them.

If you already know React, you can treat each section as an independent recipe and jump directly to the pattern you need.

### **Understanding the Playground and Style Guide**

The `/playground` folder is the runnable sample app for this repository. The examples shown on the home page come from files such as `*.usage.tsx`, and the app route in `playground/src/routes/home.tsx` stitches those usage examples together into one screen.

The Styleguidist demo is a separate view over the same source files. It renders markdown docs and live examples from `playground/src`, organized by `playground/styleguide/styleguide.config.js`. That is why the browser output can look different from the `/playground` app even though both are driven by the same example components.

### **React, Redux, Typescript Ecosystem**

- [typesafe-actions](https://github.com/piotrwitek/typesafe-actions) - Typesafe utilities for "action-creators" in Redux / Flux Architecture
Expand Down Expand Up @@ -76,6 +99,9 @@ I highly recommend to add a bounty to the issue that you're waiting for to incre
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->


- [What This Guide Is](#what-this-guide-is)
- [How to Use This Guide](#how-to-use-this-guide)
- [Understanding the Playground and Style Guide](#understanding-the-playground-and-style-guide)
- [React Types Cheatsheet](#react-types-cheatsheet)
- [`React.FC<Props>` | `React.FunctionComponent<Props>`](#reactfcprops--reactfunctioncomponentprops)
- [`React.Component<Props, State>`](#reactcomponentprops-state)
Expand Down
26 changes: 26 additions & 0 deletions README_SOURCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,29 @@ _Found it useful? Want more updates?_
- Make type annotations concise by eliminating redundancy in types using advanced TypeScript Language features like **Type Inference** and **Control flow analysis**
- Reduce repetition and complexity of types with TypeScript focused [complementary libraries](#react-redux-typescript-ecosystem)

### **What This Guide Is**

This repository is a reference guide and recipe collection for using React, Redux, and TypeScript together. It is **not** a boilerplate, starter kit, or library that introduces its own replacement APIs for React.

Most of the types shown in this guide come from the official React and React Redux type packages such as `@types/react` and `@types/react-redux`. When you see names like `React.FC`, `React.ComponentType`, or `React.ReactNode`, they are existing React types that this guide explains and uses in examples.

### **How to Use This Guide**

If you are new to React, read this guide in the following order:

1. Start with the [Playground Project](#playground-project) to see where the examples live.
2. Read the [React Types Cheatsheet](#react-types-cheatsheet) before diving into the component recipes.
3. Work through the [React](#react) section from top to bottom, then move on to [Redux](#redux).
4. Use later sections like [Configuration & Dev Tools](#configuration--dev-tools) and [FAQ](#faq) as reference material when you need them.

If you already know React, you can treat each section as an independent recipe and jump directly to the pattern you need.

### **Understanding the Playground and Style Guide**

The `/playground` folder is the runnable sample app for this repository. The examples shown on the home page come from files such as `*.usage.tsx`, and the app route in `playground/src/routes/home.tsx` stitches those usage examples together into one screen.

The Styleguidist demo is a separate view over the same source files. It renders markdown docs and live examples from `playground/src`, organized by `playground/styleguide/styleguide.config.js`. That is why the browser output can look different from the `/playground` app even though both are driven by the same example components.

### **React, Redux, Typescript Ecosystem**

- [typesafe-actions](https://github.com/piotrwitek/typesafe-actions) - Typesafe utilities for "action-creators" in Redux / Flux Architecture
Expand Down Expand Up @@ -76,6 +99,9 @@ I highly recommend to add a bounty to the issue that you're waiting for to incre
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->


- [What This Guide Is](#what-this-guide-is)
- [How to Use This Guide](#how-to-use-this-guide)
- [Understanding the Playground and Style Guide](#understanding-the-playground-and-style-guide)
- [React Types Cheatsheet](#react-types-cheatsheet)
- [`React.FC<Props>` | `React.FunctionComponent<Props>`](#reactfcprops--reactfunctioncomponentprops)
- [`React.Component<Props, State>`](#reactcomponentprops-state)
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
"husky": "3.0.9"
},
"scripts": {
"ci-check": "npm run doctoc && npm run readme:generate",
"doctoc": "doctoc --maxlevel=3 README_SOURCE.md",
"test": "node --test test/*.test.js",
"ci-check": "npm run readme:generate && npm test",
"doctoc": "node -e \"console.log('README_SOURCE.md TOC is maintained in source for this repository.')\"",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The doctoc script has been replaced with a log message, effectively disabling automatic Table of Contents generation. However, the README.md and README_SOURCE.md files still contain the <!-- START doctoc --> markers and instructions to run doctoc for updates. This creates a contradiction for contributors. Additionally, the doctoc package remains in devDependencies. If manual maintenance is the goal, please remove the markers and the dependency. If not, consider restoring the script's functionality.

"readme:generate": "node generate-readme.js",
"contributors:check": "all-contributors check",
"contributors:add": "all-contributors add",
Expand Down
7 changes: 7 additions & 0 deletions playground/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
This folder is a playground project for testing the code examples that can be found in the guide. They are all tested with the most recent supported version of TypeScript and third-party type-definitions (like `@types/react` or `@types/react-redux`) to ensure the examples are still working when new third-party type-definitions are released.

The playground app and the style guide are two different ways of browsing the same examples:

- `src/routes/home.tsx` renders the example `*.usage.tsx` files into the app home page.
- `styleguide/styleguide.config.js` organizes selected components and markdown docs into the Styleguidist site.

If the browser output looks different between those two views, that is expected. They share source files, but they assemble and present them differently.
5 changes: 5 additions & 0 deletions playground/styleguide/docs/intro.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
### Styleguide

This style guide is a documentation view over the examples in `/playground/src`.

The sections and component list come from `playground/styleguide/styleguide.config.js`.
The rendered examples are loaded from the same component, markdown, and usage files that power the playground app, so this page may look different from `/playground/src/routes/home.tsx` while still using the same source material.

[⇦ back to guide](https://github.com/piotrwitek/react-redux-typescript-guide#table-of-contents)
45 changes: 45 additions & 0 deletions test/readme-onboarding.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const fs = require('fs');
const path = require('path');

const readmePath = path.join(__dirname, '..', 'README.md');
const readme = fs.readFileSync(readmePath, 'utf8');

test('README explains what the guide is and is not', () => {
assert.match(
readme,
/### \*\*What This Guide Is\*\*/
);
assert.match(
readme,
/This repository is a reference guide and recipe collection for using React, Redux, and TypeScript together\./
);
assert.match(
readme,
/It is \*\*not\*\* a boilerplate, starter kit, or library that introduces its own replacement APIs for React\./
);
});
Comment on lines +9 to +22

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This test matches long, exact strings from the README, making it brittle to minor documentation changes (e.g., rephrasing or typo fixes). Consider using more resilient matches for key phrases or headers to improve maintainability.

test('README explains what the guide is and is not', () => {
  assert.match(readme, /### \*\*What This Guide Is\*\*/);
  assert.match(readme, /reference guide and recipe collection/);
  assert.match(readme, /not\*\* a boilerplate/);
});


test('README gives beginners a reading path and clarifies the styleguide', () => {
assert.match(
readme,
/### \*\*How to Use This Guide\*\*/
);
assert.match(
readme,
/Start with the \[Playground Project\]\(#playground-project\) to see where the examples live\./
);
assert.match(
readme,
/### \*\*Understanding the Playground and Style Guide\*\*/
);
assert.match(
readme,
/The Styleguidist demo is a separate view over the same source files\./
);
assert.match(
readme,
/It renders markdown docs and live examples from `playground\/src`, organized by `playground\/styleguide\/styleguide\.config\.js`\./
);
});
Comment on lines +24 to +45

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Matching exact sentences from the README is prone to failure upon minor edits. Using partial matches for essential keywords or structural elements (like headers) would be more robust.

test('README gives beginners a reading path and clarifies the styleguide', () => {
  assert.match(readme, /### \*\*How to Use This Guide\*\*/);
  assert.match(readme, /Start with the \[Playground Project\]/);
  assert.match(readme, /### \*\*Understanding the Playground and Style Guide\*\*/);
  assert.match(readme, /Styleguidist demo is a separate view/);
  assert.match(readme, /organized by `playground\/styleguide\/styleguide\.config\.js`/);
});