You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ We appreciate your interest in contributing to this project. Here are some core
4
4
5
5
## 📋 Core Principles
6
6
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.
8
8
9
9
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.
-[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.
40
32
41
33
---
42
34
43
-
## Basic Cheatsheet
35
+
## Cheatsheet
44
36
45
-
### Basic Cheatsheet Table of Contents
37
+
### Table of Contents
46
38
47
39
<details>
48
40
49
41
<summary><b>Expand Table of Contents</b></summary>
@@ -148,7 +139,7 @@ There are some tools that let you run React and TypeScript online, which can be
148
139
149
140
<!--END-SECTION:setup-->
150
141
151
-
### Section 2: Getting Started
142
+
### Getting Started
152
143
153
144
<!--START-SECTION:function-components-->
154
145
@@ -618,8 +609,6 @@ If you are writing a React Hooks library, don't forget that you should also expo
618
609
-https://github.com/palmerhq/the-platform
619
610
-https://github.com/sw-yx/hooks
620
611
621
-
[Something to add? File an issue](https://github.com/typescript-cheatsheets/react/issues/new).
622
-
623
612
<!--END-SECTION:hooks-->
624
613
625
614
<!--START-SECTION:class-components-->
@@ -729,8 +718,6 @@ class App extends React.Component<{
729
718
730
719
[View in the TypeScript Playground](https://www.typescriptlang.org/play/?jsx=2#code/JYWwDg9gTgLgBAJQKYEMDG8BmUIjgcilQ3wFgAoCtAGxQGc64BBMMOJADxiQDsATRsnQwAdAGFckHrxgAeAN4U4cEEgYoA5kgBccOjCjAeGgNwUAvgD44i8sshHuUXTwCuIAEZIoJuAHo-OGpgAGskOBgAC2A6JTg0SQhpHhgAEWA+AFkIVxSACgBKGzjlKJiRBxTvOABeOABmMzs4cziifm9C4ublIhhXKB44PJLlOFk+YAA3S1GxmzK6CpwwJdV1LXM4FH4F6KXKp1aesdk-SZnRgqblY-MgA)
731
720
732
-
[Something to add? File an issue](https://github.com/typescript-cheatsheets/react/issues/new).
733
-
734
721
#### Typing getDerivedStateFromProps
735
722
736
723
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
874
861
875
862
</details>
876
863
877
-
[Something to add? File an issue](https://github.com/typescript-cheatsheets/react/issues/new).
childrenElement:React.JSX.Element; // A single React element
971
956
style?:React.CSSProperties; // to pass through style props
972
957
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
974
959
props:Props&React.ComponentPropsWithoutRef<"button">; // to impersonate all the props of a button element and explicitly not forwarding its ref
975
960
props2:Props&React.ComponentPropsWithRef<MyButtonWithForwardRef>; // to impersonate all the props of MyButtonForwardedRef and explicitly forwarding its ref
976
961
}
@@ -988,8 +973,6 @@ Quote [@ferdaber](https://github.com/typescript-cheatsheets/react/issues/57): A
988
973
989
974
[More discussion: Where ReactNode does not overlap with React.JSX.Element](https://github.com/typescript-cheatsheets/react/issues/129)
990
975
991
-
[Something to add? File an issue](https://github.com/typescript-cheatsheets/react/issues/new).
992
-
993
976
#### Types or Interfaces?
994
977
995
978
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:
"@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
-
2047
1921
## My question isn't answered here!
2048
1922
2049
1923
-[File an issue](https://github.com/typescript-cheatsheets/react-typescript-cheatsheet/issues/new).
0 commit comments