Skip to content

Commit 62abf7b

Browse files
restructure menu (#820)
1 parent c276c58 commit 62abf7b

30 files changed

Lines changed: 56 additions & 1285 deletions

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ We appreciate your interest in contributing to this project. Here are some core
44

55
## 📋 Core Principles
66

7-
1. **We're All About Cheatsheets**: Our main goal is to provide concise and easy-to-use cheatsheets. All code examples should be simple, easily searchable, and ready for copy-and-paste.
7+
1. **Cheatsheet Style**: Our main goal is to provide a concise and easy-to-use cheatsheet. All code examples should be simple, easily searchable, and ready for copy-and-paste.
88

99
2. **Collapsible Explanations**: Keep explanations short and sweet, limited to 1-2 sentences. For more in-depth explanations, use `details` tags to provide additional context.
1010

README.md

Lines changed: 15 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -24,38 +24,30 @@ Cheatsheet for using React with TypeScript.
2424

2525
[![All Contributors](https://img.shields.io/github/contributors/typescript-cheatsheets/react-typescript-cheatsheet?color=orange&style=flat-square)](/CONTRIBUTORS.md) | [![Discord](https://img.shields.io/discord/508357248330760243.svg?label=&logo=discord&logoColor=ffffff&color=7389D8&labelColor=6A7EC2)](https://discord.gg/wTGS5z9)
2626

27-
- [The Basic Cheatsheet](https://react-typescript-cheatsheet.netlify.app/docs/basic/setup) is focused on helping React devs just start using TS in React **apps**
28-
- Focus on opinionated best practices, copy+pastable examples.
29-
- Explains some basic TS types usage and setup along the way.
30-
- Answers the most Frequently Asked Questions.
31-
- Does not cover generic type logic in detail. Instead we prefer to teach simple troubleshooting techniques for newbies.
32-
- The goal is to get effective with TS without learning _too much_ TS.
33-
- [The Advanced Cheatsheet](https://react-typescript-cheatsheet.netlify.app/docs/advanced) helps show and explain advanced usage of generic types for people writing reusable type utilities/functions/render prop/higher order components and TS+React **libraries**.
34-
- It also has miscellaneous tips and tricks for pro users.
35-
- Advice for contributing to DefinitelyTyped.
36-
- The goal is to take _full advantage_ of TypeScript.
37-
- [The HOC Cheatsheet](https://react-typescript-cheatsheet.netlify.app/docs/hoc) specifically teaches people to write HOCs with examples.
38-
- Familiarity with [Generics](https://www.typescriptlang.org/docs/handbook/2/generics.html) is necessary.
39-
- ⚠️This is the newest cheatsheet, all assistance is welcome.
27+
[The Cheatsheet](https://react-typescript-cheatsheet.netlify.app/docs/basic/setup) is focused on helping React devs use TypeScript effectively:
28+
29+
- Opinionated best practices and copy+pastable examples.
30+
- Covers basic TS types and setup, plus advanced usage of generic types for people writing reusable type utilities and React+TS **libraries**.
31+
- Advice for contributing to DefinitelyTyped.
4032

4133
---
4234

43-
## Basic Cheatsheet
35+
## Cheatsheet
4436

45-
### Basic Cheatsheet Table of Contents
37+
### Table of Contents
4638

4739
<details>
4840

4941
<summary><b>Expand Table of Contents</b></summary>
5042

5143
- [React TypeScript Cheatsheet](#react-typescript-cheatsheet)
52-
- [Basic Cheatsheet](#basic-cheatsheet)
53-
- [Basic Cheatsheet Table of Contents](#basic-cheatsheet-table-of-contents)
54-
- [Section 1: Setup](#section-1-setup)
44+
- [Cheatsheet](#cheatsheet)
45+
- [Table of Contents](#table-of-contents)
46+
- [Setup](#setup)
5547
- [Prerequisites](#prerequisites)
5648
- [React and TypeScript starter kits](#react-and-typescript-starter-kits)
5749
- [Try React and TypeScript online](#try-react-and-typescript-online)
58-
- [Section 2: Getting Started](#section-2-getting-started)
50+
- [Getting Started](#getting-started)
5951
- [Function Components](#function-components)
6052
- [Hooks](#hooks)
6153
- [useState](#usestate)
@@ -106,15 +98,14 @@ Cheatsheet for using React with TypeScript.
10698
- [Option 1: Using react-error-boundary](#option-1-using-react-error-boundary)
10799
- [Option 2: Writing your custom error boundary component](#option-2-writing-your-custom-error-boundary-component)
108100
- [Concurrent React/React Suspense](#concurrent-reactreact-suspense)
109-
- [Linting](#linting)
110101
- [My question isn't answered here!](#my-question-isnt-answered-here)
111102
- [Contributors](#contributors)
112103

113104
</details>
114105

115106
<!--START-SECTION:setup-->
116107

117-
### Section 1: Setup
108+
### Setup
118109

119110
#### Prerequisites
120111

@@ -148,7 +139,7 @@ There are some tools that let you run React and TypeScript online, which can be
148139

149140
<!--END-SECTION:setup-->
150141

151-
### Section 2: Getting Started
142+
### Getting Started
152143

153144
<!--START-SECTION:function-components-->
154145

@@ -618,8 +609,6 @@ If you are writing a React Hooks library, don't forget that you should also expo
618609
- https://github.com/palmerhq/the-platform
619610
- https://github.com/sw-yx/hooks
620611

621-
[Something to add? File an issue](https://github.com/typescript-cheatsheets/react/issues/new).
622-
623612
<!--END-SECTION:hooks-->
624613

625614
<!--START-SECTION:class-components-->
@@ -729,8 +718,6 @@ class App extends React.Component<{
729718

730719
[View in the TypeScript Playground](https://www.typescriptlang.org/play/?jsx=2#code/JYWwDg9gTgLgBAJQKYEMDG8BmUIjgcilQ3wFgAoCtAGxQGc64BBMMOJADxiQDsATRsnQwAdAGFckHrxgAeAN4U4cEEgYoA5kgBccOjCjAeGgNwUAvgD44i8sshHuUXTwCuIAEZIoJuAHo-OGpgAGskOBgAC2A6JTg0SQhpHhgAEWA+AFkIVxSACgBKGzjlKJiRBxTvOABeOABmMzs4cziifm9C4ublIhhXKB44PJLlOFk+YAA3S1GxmzK6CpwwJdV1LXM4FH4F6KXKp1aesdk-SZnRgqblY-MgA)
731720

732-
[Something to add? File an issue](https://github.com/typescript-cheatsheets/react/issues/new).
733-
734721
#### Typing getDerivedStateFromProps
735722

736723
Before you start using `getDerivedStateFromProps`, please go through the [documentation](https://reactjs.org/docs/react-component.html#static-getderivedstatefromprops) and [You Probably Don't Need Derived State](https://reactjs.org/blog/2018/06/07/you-probably-dont-need-derived-state.html). Derived State can be implemented using hooks which can also help set up memoization.
@@ -874,8 +861,6 @@ For most apps this isn't needed — only library authors who re-export the props
874861

875862
</details>
876863

877-
[Something to add? File an issue](https://github.com/typescript-cheatsheets/react/issues/new).
878-
879864
<!--END-SECTION:default-props-->
880865

881866
<!--START-SECTION:basic-type-examples-->
@@ -970,7 +955,7 @@ export declare interface AppProps {
970955
childrenElement: React.JSX.Element; // A single React element
971956
style?: React.CSSProperties; // to pass through style props
972957
onChange?: React.FormEventHandler<HTMLInputElement>; // form events! the generic parameter is the type of event.target
973-
// more info: https://react-typescript-cheatsheet.netlify.app/docs/advanced/patterns_by_usecase/#wrappingmirroring
958+
// more info: https://react-typescript-cheatsheet.netlify.app/docs/basic/getting-started/patterns_by_usecase/#wrappingmirroring
974959
props: Props & React.ComponentPropsWithoutRef<"button">; // to impersonate all the props of a button element and explicitly not forwarding its ref
975960
props2: Props & React.ComponentPropsWithRef<MyButtonWithForwardRef>; // to impersonate all the props of MyButtonForwardedRef and explicitly forwarding its ref
976961
}
@@ -988,8 +973,6 @@ Quote [@ferdaber](https://github.com/typescript-cheatsheets/react/issues/57): A
988973

989974
[More discussion: Where ReactNode does not overlap with React.JSX.Element](https://github.com/typescript-cheatsheets/react/issues/129)
990975

991-
[Something to add? File an issue](https://github.com/typescript-cheatsheets/react/issues/new).
992-
993976
#### Types or Interfaces?
994977

995978
You can use either Types or Interfaces to type Props and State, so naturally the question arises - which do you use?
@@ -1038,8 +1021,6 @@ It's a nuanced topic, don't get too hung up on it. Here's a handy table:
10381021

10391022
(source: [Karol Majewski](https://twitter.com/karoljmajewski/status/1082413696075382785))
10401023

1041-
[Something to add? File an issue](https://github.com/typescript-cheatsheets/react/issues/new).
1042-
10431024
<!--END-SECTION:basic-type-examples-->
10441025

10451026
<!--START-SECTION:get-derived-state-from-props-->
@@ -1443,7 +1424,7 @@ function Parent() {
14431424
}
14441425
```
14451426

1446-
**Read more**: [Wrapping/Mirroring a HTML Element](/docs/advanced/patterns_by_usecase#wrappingmirroring-a-html-element)
1427+
**Read more**: [Wrapping/Mirroring a HTML Element](/docs/basic/getting-started/patterns_by_usecase#wrappingmirroring-a-html-element)
14471428

14481429
#### Legacy Approaches (Pre-React 19)
14491430

@@ -1782,8 +1763,6 @@ export default ErrorBoundary;
17821763

17831764
```
17841765

1785-
[Something to add? File an issue](https://github.com/typescript-cheatsheets/react/issues/new).
1786-
17871766
<!--END-SECTION:error-boundaries-->
17881767

17891768
<!--START-SECTION:concurrent-->
@@ -1937,113 +1916,8 @@ The standalone version does not provide an `isPending` flag — use the hook if
19371916
- [`useActionState`, `useFormStatus`, `useOptimistic`](https://react.dev/reference/react) — built on top of transitions
19381917
- [Server Components and `'use server'`](https://react.dev/reference/rsc/server-components)
19391918

1940-
[Something to add? File an issue](https://github.com/typescript-cheatsheets/react/issues/new).
1941-
19421919
<!--END-SECTION:concurrent-->
19431920

1944-
<!--START-SECTION:linting-->
1945-
1946-
### Linting
1947-
1948-
Follow the TypeScript + ESLint docs at https://github.com/typescript-eslint/typescript-eslint:
1949-
1950-
```
1951-
yarn add -D @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint
1952-
```
1953-
1954-
add a `lint` script to your `package.json`:
1955-
1956-
```json
1957-
"scripts": {
1958-
"lint": "eslint 'src/**/*.ts'"
1959-
},
1960-
```
1961-
1962-
and a suitable `.eslintrc.js` (using `.js` over `.json` here so we can add comments):
1963-
1964-
```js
1965-
module.exports = {
1966-
env: {
1967-
es6: true,
1968-
node: true,
1969-
jest: true,
1970-
},
1971-
extends: "eslint:recommended",
1972-
parser: "@typescript-eslint/parser",
1973-
plugins: ["@typescript-eslint"],
1974-
parserOptions: {
1975-
ecmaVersion: 2017,
1976-
sourceType: "module",
1977-
},
1978-
rules: {
1979-
indent: ["error", 2],
1980-
"linebreak-style": ["error", "unix"],
1981-
quotes: ["error", "single"],
1982-
"no-console": "warn",
1983-
"no-unused-vars": "off",
1984-
"@typescript-eslint/no-unused-vars": [
1985-
"error",
1986-
{ vars: "all", args: "after-used", ignoreRestSiblings: false },
1987-
],
1988-
"@typescript-eslint/explicit-function-return-type": "warn", // Consider using explicit annotations for object literals and function return types even when they can be inferred.
1989-
"no-empty": "warn",
1990-
},
1991-
};
1992-
```
1993-
1994-
Most of this is taken from [the `tsdx` PR](https://github.com/palmerhq/tsdx/pull/70/files) which is for **libraries**.
1995-
1996-
More `.eslintrc.json` options to consider with more options you may want for **apps**:
1997-
1998-
```json
1999-
{
2000-
"extends": [
2001-
"airbnb",
2002-
"prettier",
2003-
"prettier/react",
2004-
"plugin:prettier/recommended",
2005-
"plugin:jest/recommended",
2006-
"plugin:unicorn/recommended"
2007-
],
2008-
"plugins": ["prettier", "jest", "unicorn"],
2009-
"parserOptions": {
2010-
"sourceType": "module",
2011-
"ecmaFeatures": {
2012-
"jsx": true
2013-
}
2014-
},
2015-
"env": {
2016-
"es6": true,
2017-
"browser": true,
2018-
"jest": true
2019-
},
2020-
"settings": {
2021-
"import/resolver": {
2022-
"node": {
2023-
"extensions": [".js", ".jsx", ".ts", ".tsx"]
2024-
}
2025-
}
2026-
},
2027-
"overrides": [
2028-
{
2029-
"files": ["**/*.ts", "**/*.tsx"],
2030-
"parser": "typescript-eslint-parser",
2031-
"rules": {
2032-
"no-undef": "off"
2033-
}
2034-
}
2035-
]
2036-
}
2037-
```
2038-
2039-
Another great resource is ["Using ESLint and Prettier in a TypeScript Project"](https://dev.to/robertcoopercode/using-eslint-and-prettier-in-a-typescript-project-53jb) by @robertcoopercode.
2040-
2041-
Wes Bos is also working on [TypeScript support for his eslint+prettier config.](https://github.com/wesbos/eslint-config-wesbos/issues/68)
2042-
2043-
If you're looking for information on Prettier, check out the [Prettier](https://github.com/typescript-cheatsheets/react/blob/main/docs/advanced/misc-concerns.md#prettier) guide.
2044-
2045-
<!--END-SECTION:linting-->
2046-
20471921
## My question isn't answered here!
20481922

20491923
- [File an issue](https://github.com/typescript-cheatsheets/react-typescript-cheatsheet/issues/new).

docs/advanced/index.md

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)